Tell us what’s happening:
Hi,
trying to work out the FALSE BOUNCER algorithm I came out with this behaviour that I cannot relate with anything I have seen. I think I understood that if you .push something in an array that you are traversing with a loop method it generates an infinite loop but why this returns the length of the array plus 1 while I was expecting to see the array plus 9 of *?
function bouncer(arr) {
for (let i = 0; i<arr.length; i++){
arr = arr.push('*');
}
console.log(arr);
}
bouncer([1,2,3,4,5,6,8,9,456]);
I tried to understand but in vain
L
Your code so far
function bouncer(arr) {
for (let i = 0; i<arr.length; i++){
arr = arr.push('*');
}
console.log(arr);
}
bouncer([1,2,3,4,5,6,8,9,456]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36
.
Challenge: Falsy Bouncer
Link to the challenge: