Skip to content

Instantly share code, notes, and snippets.

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 robotlolita/3172348 to your computer and use it in GitHub Desktop.
Save robotlolita/3172348 to your computer and use it in GitHub Desktop.
Creating n sized lists
function last(xs){ return xs[xs.length - 1] }
function split(predicate, xs) {
return reduce( xs
, function(rv, x, i) { return predicate(x, i)? rv.concat([[x]])
: /* otherwise */ (last(rv).push(x), rv) }
, [[ ]]) }
function splitEvery(n, xs) { return split(function(x, i){ return i > 0 && i % n == 0 }, xs) }
// reduce is Array.prototype.reduce.call.bind(Array.prototype.reduce)
reduce(list, intoTriplet, [])
reduce(list, intoTuple, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment