Remove Items from an Array with pop() and shift() help

Tell us what’s happening:
can somebody please help me qith this?? im stuck! :confused:

Your code so far

function popShift(arr) {
  let popped = ['not','complete']; // change this line
  let shifted = ['challende','is']; // change this line
  return [shifted, popped];

// 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

You have to use the pop() and shift() methods, like given in the example,

We can also return the value of the removed element with either method like this:

let greetings = ['whats up?', 'hello', 'see ya!'];

let popped = greetings.pop();
// returns 'hello'
// greetings now equals []

So all you need to do, is to apply these two methods on the arg passed to the function

this i dont understand.

You are just creating an array with the values and passing it to the return statement, it shouldn’t be that way,

You have to get those values from arr using pop() and shift()

Instead of greetings place arr since that contains the array values,
It will pop the array and give the last element value
Do the same for shift to get the first element of arr, the example shows the exact syntax of pop, you should just replace it with the correct array name, arr in this case

Well, the simple thing is you’re misspelling “challenge” as “challende”.

But @Sujith3021 is exactly correct. You are being passed an array of strings, and may be passed completely different strings, but the pattern to handle them needs to be the same.

To handle this, you need to understand what Array.pop() and Array.shift() are doing, and what they are returning. In order to handle this particular challenge, you need to intercept that returned value, and do something with it.

Would you say you grok Array.shift() and Array.pop() ? Do you understand the difference?

1 Like