Created
August 24, 2019 04:49
-
-
Save paitonic/3884099d9ffaf9341038a35ea88d38b1 to your computer and use it in GitHub Desktop.
chunk
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
function chunk(array, size) { | |
function partition(array, start, result=[]) { | |
if (array.length === 0) { | |
return result; | |
} | |
return partition(array.slice(start+size, array.length), start+size, [...result, array.slice(0, size)]) | |
} | |
return partition(array, 0); | |
} | |
chunk([1, 2, 3, 4, 5], 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment