Created
July 24, 2012 19:13
-
-
Save Raynos/3171982 to your computer and use it in GitHub Desktop.
Creating n sized lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// curry is ncurry(2) | |
var intoList = curry(function (size, list, elem) { | |
var lastElem = last(list) | |
if (lastElem && lastElem.length < size) { | |
lastElem.push(elem) | |
} else { | |
list.push([elem]) | |
} | |
return list | |
}) | |
, intoTriplet = intoList(3) | |
, intoTuple = intoList(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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