Forked from anonymous/bonfire-steamroller.js
Created
December 11, 2015 11:54
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Steamroller
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
// 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