Last active
December 21, 2015 08:29
-
-
Save ralphsaunders/6278593 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
core.chunk = function (array, chunkSize) { | |
/// <summary> | |
/// Splits a given array into separate arrays of the given chunkSize | |
/// </summary> | |
/// <param name="array" type="array"></param> | |
/// <param name="chunkSize" type="number"></param> | |
/// <returns type="array"></returns> | |
var count = 1; | |
var newArray = []; | |
var limit = chunkSize; | |
var tempArray = []; | |
for (var i = 0; i < array.length ; i++) { | |
if (i < limit) { | |
tempArray.push(array[i]); | |
if (i == array.length - 1) { | |
newArray.push(tempArray); | |
tempArray = []; | |
} | |
} | |
else { | |
newArray.push(tempArray); | |
tempArray = []; | |
tempArray.push(array[i]); | |
count = count + 1; | |
limit = chunkSize * (count); | |
} | |
} | |
return newArray; | |
} |
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
def chunk(list, n): | |
# Split list into chunks of n size | |
return [list[i:i+n] for i in range(0, len(list), n)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment