Toggle navigation shitcode
  • Latest
  • Browse
  • Top
  • Worst
  • Add
  • All 496
  • ActionScript 3
  • Bash 7
  • Brainfuck 1
  • LSL 21
  • C++ 35
  • C# 54
  • CSS 5
  • Pascal 1
  • Django 1
  • Erlang 1
  • GLSL 1
  • Go 7
  • Groovy 1
  • HTML 10
  • Java 76
  • JavaScript 105
  • Less 1
  • Lua 3
  • Nix 1
  • Obj-C 4
  • OCaml 1
  • Perl 1
  • PHP 74
  • PowerShell 1
  • Python 46
  • Ruby 3
  • Rust 2
  • Scala 3
  • SQL 7
  • Swift 4
  • TypeScript 13
  • VBScript 2
  • Verilog 1
#279 OCaml String Length OCaml 0
let length str =
    let len = String.length str in
    
    let rec length_helper str curr = 
    if str = "" then 0 else 1 + length_helper (String.sub str 1 (len - curr - 1)) (curr + 1)
    
    in length_helper str 0;;

We use this code internally at Google. JFC.

Comments
By Mark, 2018-04-21 21:51:57

© Shitcode.net 2026, Powered by Yii Framework

GitHub • About • Admin