Created
September 11, 2015 21:51
-
-
Save sisodiakaran/be5b25a26dd80332cbe3 to your computer and use it in GitHub Desktop.
JS Recursive Function
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
var home = { | |
room_1: { | |
tube: 5, | |
fan: 6, | |
lamp: { | |
one: 7, | |
two: { | |
two_1: 8, | |
tow_two: 9 | |
} | |
} | |
} | |
}; | |
var a = []; | |
var recursive_setup = function(start) { | |
var b = []; | |
if (typeof start !== "object") { | |
a.push(start); | |
} else { | |
for (i in start) { | |
b.push(recursive_setup(start[i])); | |
} | |
} | |
return a; | |
}; | |
console.log(recursive_setup(home)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment