|
Edit: Oh, and as for the question itself, no I would not
call it a recursive function just because it calls itself;
I'd call it a self-referencing function. Where recursive functions are a subset of self-referencing functions. 1. Why does it matter? 2. Your first example I would simply call an asynchronous loop. 3. Your second example could possibly be called single recursion. 4. Recursion should at least consist of a base case and a recursive case, each self-reference should bring the input value closer to the base case which would end the recursion. (Your second example has a recursive case and falls out into an undefined base case). 5. An example of 4 would be a tree structure where the base case is a leaf and recursion cases are branches. function walk (value) {
if (Array.isArray(value)) {
value.forEach(walk);
} else {
console.log(value);
}
}
walk([[[1, 2, 3, [4, 5, 6]]],[[7, [8, 9, 10], 11, [12]]],13,14]);
would output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |