Stand in Line - questions! RESOLVE! THANKS!

Stand in Line - questions! RESOLVE! THANKS!
0

#1

Tell us what’s happening:

Hi, I have a question, I wanna know why is not the same write this:

function nextInLine(arr, item) {
var queue = arr.push(item)
var rItem = arr.shift()
return rItem;
}

and write this:

function nextInLine(arr, item) {
var aux = item
item = arr[0]
arr[0] = item
return item;
}

this is my first time trying to code, please help me! ^^

Your code so far

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

// 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));

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:


#2

The second solution does not change the arr passed into it.

I will break the code inside your function down line by line:

var aux = item; // assigns the value 6 to variable aux - You never use this again for some reason

item = arr[0]; // assigns the value of 1 to item;

arr[0] = item; replaces the first item in arr with the number 1 (the current value of item)

return item; // returns the number 1

Your code above never adds the value 6 as a new element onto the end of arr and it does not remove the first item (the number 1) from arr. That is why it does not accomplish the same thing as the first solution.