Remove Items from an Array with pop() and shift() What's wrong?

Tell us what’s happening:

It says that the return should be “challenge”, “complete”. But since on the return I put arr.shift (that should be ‘challenge’) and arr.pop (that should be complete") then shouldn’t it say “Challenge Complete” ?
I also tried
" let popped = arr.shift(), arr.pop();"
but it says the same.
Thank you for your patience!

Your code so far


function popShift(arr) {
  arr.shift(); // change this line
  arr.pop(); // change this line
  return [arr.shift() , arr.pop()];
}

// do not change code below this line
console.log(popShift(["challenge", 'is', 'not', "complete"]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/remove-items-from-an-array-with-pop-and-shift

Hey @taniacrispim0,

After you execute this code,
Your arr is ["is","not"] .

While you are returning here,
you perform the pop and shift again on the arr which is ["is","not"] .
So, your array becomes empty and these values are returned.
Does that answer your question?

1 Like

you changed the code too much. You should not erase the 2 let statements that were there already.
and you should not change the return statement.
Just reset the code and add the pop and shift statement to the code that is already there.

2 Likes

@aditya_p Thank you so much for the help :slight_smile: I finally understood that it was " “is”, “not” " because the way i was doing it didn’t returned the words that I wanted (and because of that only returned the words that were left).
@hbar1st thank you! that worked! basically what i’m doing is saying= let popped be “challenge” and let shifted be “complete” right? (from what i understood) while in the first one i was basically saying “delete these words and just put the ones that remain”.

1 Like