Last active
August 29, 2015 14:22
-
-
Save obiPlabon/8c95ae7e7bde1961d23a to your computer and use it in GitHub Desktop.
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
// | |
// @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