Created
April 8, 2019 11:40
-
-
Save jalada/59e21719ab2684cfba88b42ab4e98c20 to your computer and use it in GitHub Desktop.
Reverse 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
const chunk = function(array, size) { | |
var length = array.length; | |
var index = length, | |
result = Array(Math.ceil(length / size)), | |
resIndex = result.length-1; | |
var start; | |
while (index > 0) { | |
start = Math.max(0, index - size); | |
result[resIndex--] = array.slice(start, index); | |
index = start; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment