Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active August 29, 2015 14:22
Show Gist options
  • Save obiPlabon/8c95ae7e7bde1961d23a to your computer and use it in GitHub Desktop.
Save obiPlabon/8c95ae7e7bde1961d23a to your computer and use it in GitHub Desktop.
//
// @pram a Array
//
var a = [1,2,3,[4,5,6,[7,8,9]]];
function recursiveMulti(a){
return a.map(function(i){
if(Object.prototype.toString.call(i) === "[object Array]")
return recursiveMulti(i);
return i * 2;
});
}
// Recursively use map on multi dimensional array
// hence recursive map (I know, you already know)
// just kidding :P
function walkRecursive(array, cb){
return array.map(function(value, index, arr){
if(Object.prototype.toString.call(value) === "[object Array]")
return walkRecursive(value, cb);
return cb(value, index, arr);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment