Why this solution of task drop it work and similar my not?

Why this solution of task drop it work and similar my not?

 while(!func(arr[0])) {
        arr.shift();
    }	
    return arr;
  var boo = false;
      while( boo === false || arr.length >0){
   boo= func(arr[0]) ;
   if(boo === false){
     arr = arr.shift();
   }

but with slice(1) yes?

can you send a link of it… coz i dont understand your code.

The while loop seems to run forever.

https://www.freecodecamp.org/challenges/drop-it

var boo = false;
while( boo === false && arr.length > 0){
boo= func(arr[0]) ;
if(boo === false){
arr.shift();
}
}
return arr;

the shift method does not return the array . It just shifts the element from the array and returns the shifted element.
and you had to have && on the condition otherwise it will may run into infinite loop

1 Like

Aha, So the elements in arr was only one after first shift

the elements in array was one less than previous number in the array.

The function however besides from poping out the first element of the array , also returns the popped out element.

But when you assigned the popped out element of the array to the arr variable itself, the arr variable now got the value of the shifted element .