Last active
January 4, 2017 14:36
-
-
Save onionmk2/49c424332fb53d43319f733043d19a32 to your computer and use it in GitHub Desktop.
recursive function call
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
const arr = | |
[ | |
[ | |
[1, 2, 3], | |
[4, 5, 6], | |
], | |
[ | |
[7, 8, 9], | |
[10, 11, 12], | |
] | |
]; | |
const isNumberArray = (arr) => { | |
return arr.every(item => { | |
return typeof(item) === 'number' && !Number.isNaN(item); | |
}) | |
}; | |
const walk1 = (arr) => { | |
if (isNumberArray(arr)) { | |
console.log(`arr is [${arr}]. walk ended.`); | |
} else { | |
for (const a of arr) { | |
walk1(a); | |
} | |
} | |
} | |
function walk2(arr) { | |
if (isNumberArray(arr)) { | |
console.log(`arr is [${arr}]. walk ended.`); | |
} else { | |
for (const a of arr) { | |
walk2(a); | |
} | |
} | |
} | |
walk1(arr); | |
walk2(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
どちらでも再帰できる。