Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2015 11:54
Show Gist options
  • Save anonymous/2931f499dfdf84c69808 to your computer and use it in GitHub Desktop.
Save anonymous/2931f499dfdf84c69808 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Steamroller
// Bonfire: Steamroller
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-steamroller
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function steamroller(arr) {
// I'm a steamroller, baby
var newArr = [];
var flatten = function(x){
if(!Array.isArray(x)){
newArr.push(x);
} else {
for(var a in x){
flatten(x[a]);
}
}
};
arr.forEach(flatten);
return newArr;
}
steamroller([1, [2], [3, [[4]]]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment