Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save anonymous/214351889e0d1bd2c384 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/214351889e0d1bd2c384 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mushfick 's solution for Bonfire: Chunky Monkey
// Bonfire: Chunky Monkey
// Author: @mushfick
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20var%20newArray%20%3D%20%5B%5D%3B%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%3B%20i%20%2B%3D%20size)%20%7B%0A%20%20%20%20newArray.push(arr.slice(i%2C%20i%20%2B%20size))%3B%0A%20%20%7D%0A%20%20return%20newArray%3B%0A%7D%0A%0Achunk(%5B0%2C%201%2C%202%2C%203%2C%204%2C%205%5D%2C%202)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
// Break it up.
var newArray = [];
for(var i = 0; i < arr.length; i += size) {
newArray.push(arr.slice(i, i + size));
}
return newArray;
}
chunk([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