Forked from anonymous/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20var%20result%20%3D%20%5B%5D%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%2Fsize%3B%20i%2B%2B)%20%7B%0A%20%20%20%20result.p
Created
November 10, 2015 21:09
-
-
Save sawant/d554dde24d5b0c9726c4 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/sawant 's solution for Bonfire: Chunky Monkey
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
// Bonfire: Chunky Monkey | |
// Author: @sawant | |
// 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%20result%20%3D%20%5B%5D%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%2Fsize%3B%20i%2B%2B)%20%7B%0A%20%20%20%20result.push(%20arr.slice(%20i%20*%20size%2C%20size%20*%20(i%2B1)%20)%20)%3B%0A%20%20%7D%0A%0A%20%20return%20result%3B%0A%7D%0A%0Achunk(%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%5D%2C%202)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function chunk(arr, size) { | |
// Break it up. | |
var result = []; | |
for (var i = 0; i < arr.length/size; i++) { | |
result.push( arr.slice( i * size, size * (i+1) ) ); | |
} | |
return result; | |
} | |
chunk(["a", "b", "c", "d"], 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment