Stuck on Stand in Line

Stuck on Stand in Line
0.0 0

#1

I’m not sure if I even understand the question correct or not but I have no confidence at all so sorry if the code is atrocious because I didn’t know what to do within 5 minutes. I have an idea of what I have to do but I don’t know how to put it all together if that makes sense.

Here you go

function nextInLine(arr, item) {
  // Your code here
  var arrayPush = arr.push();
  arrayPush = arr.shift();
  item = arrayPush;
  
  return item;  // Change this line
}

nextInline([2], 1);

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

#2

You’re close, but look at how Array.push() works.


#3

How close am I? Which parts did I get correct? I’m still quite stuck to be honest.


#4

Your line using push() is wrong. Look at how the push function works.


#5

is this correct?

arr.push(item);


#6

Ok this is what I done so far

function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  var removed = arr.shift();
  item = removed;
  
  
  return item;  // Change this line
}

nextInline([5,6,7,8,9], 1);

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));


#7

That should work.

You can replace

item = removed;
  
  
  return item;  // Change this line

with

return removed;

#8

I done it but it still says it ain’t working


function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  var removed = arr.shift();
  
  
  return removed;  // Change this line
}

nextInline([5,6,7,8,9], 1);

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));


#9

Never mind I just completed it thank-you.