Last active
August 9, 2019 02:10
-
-
Save krainboltgreene/518452ef2b5278d1da9bc04753e3303c to your computer and use it in GitHub Desktop.
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
const chunk = | |
(maximum) => | |
(list) => | |
reduceWithValueKey( | |
(accumulated) => | |
(item) => | |
(index) => { | |
const [latestChunk, ...previousChunks] = accumulated; | |
if ((length(latestChunk) !== maximum) && (length(list) === index + 1)) { | |
return reverse([[...latestChunk, item], ...previousChunks]); | |
} | |
if (length(list) === index + 1) { | |
return reverse([[item], ...accumulated]); | |
} | |
if (length(latestChunk) !== maximum) { | |
return [[...latestChunk, item], ...previousChunks] | |
} | |
return [[item], ...accumulated]; | |
} | |
)( | |
[[]] | |
)( | |
list | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment