let data = [1, 2, 3]
let sorted = []
let push = function(i) {
while(i<data.length) {
sorted.push(data[i])
push(i + 1)
}
}
push(0)
Hey there,
I am experimenting with some recursive code and it seems to be stuck in an endless loop. Apologies for the novice question, but I would appreciate if someone could shed some light on this.
Expected outcome: Should simulate a for loop by iterating over an array and pushing elements to a new array. It should stop when reaching i == data.length
Current behavior: It iterates for 0, 1, 2, then back to 2 until hitting a stack overflow.
Codefiddle link: https://jsfiddle.net/t579jbog/