Skip to content

Instantly share code, notes, and snippets.

@mayth
Created December 4, 2014 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayth/f5c8bfacf6f09a6c92f9 to your computer and use it in GitHub Desktop.
Save mayth/f5c8bfacf6f09a6c92f9 to your computer and use it in GitHub Desktop.
Slice array
let slice n arr =
let len = int (ceil ((float (Array.length arr)) / (float n)))
Array.init len (fun i -> arr.[(i * n)..(i * n + (n - 1))])
// test code
[<EntryPoint>]
let main args =
let arr = [|1; 2; 3; 10; 20; 30; 100; 200; 300|]
let result = slice 3 arr
printfn "%A" result
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment