Tell us what’s happening:
Hey good folks! I was hoping you could tell me if I am thinking of this the right way?
This was giving me some headache. But I think I figured it out.
function nextInLine(arr, item) {
// A function named nextInLine. Inside the parenthesis is parameters that act as placeholders for arguments thats defined when we call the function.
arr.push(item);
// This one was troubling me. But is it right that here we are saying: Insert the “item” argument at the back of the line?
return arr.shift();
// After inserting the “item” at the back of the line, return the “arr” argument, but at the same time, remove the first item? Otherwise we would have six numbers in the array?
}
// Test Setup
var testArr = [1,2,3,4,5];
// This is a variable with array
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
// Here we call the nextInLine and pass the argument "testArr and the number 6. That gives us 2,3,4,5,6 in the “testArr” variable?
console.log("After: " + JSON.stringify(testArr));
Thanks so much!
Your code so far
function nextInLine(arr, item) {
// Your code here
arr.push(item);
return arr.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 50)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
.
Link to the challenge: