Created
June 18, 2016 03:28
-
-
Save twhite96/75e1dab5c8683ac22197487bd718b0a4 to your computer and use it in GitHub Desktop.
Chunky Monkey algorithm Free Code Camp solution
This file contains 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 chunkArrayInGroups(arr, size) { | |
var newArray = []; | |
var oldArray = arr.length/size; | |
for (var i = 0; i < oldArray; i++) { | |
var array = arr.splice(0, size); | |
newArray.push(array); | |
} | |
return newArray; | |
// Break it up. | |
} | |
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write a function that splits an array (first argument) into groups the length of
size
(second argument) and returns them as a two-dimensional array.Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Array.push()
Array.slice()