Stand in line
FCC Next in line queue style function
HTML
<h3>Stand in line</h3>
<p>
In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue.
</p>
<p>
Write a function nextInLine which takes an array <pre>(arr)</pre> and a number <pre>(item)</pre> as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.</p>
<p id="demo"></p>
<p id="demo2"></p>
<p id="demo3"></p>
JavaScript
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
document.getElementById("demo").innerHTML = ("Before: " + JSON.stringify(testArr));
document.getElementById("demo2").innerHTML = (nextInLine(testArr, 6)); // Modify this line to test
document.getElementById("demo3").innerHTML = ("After: " + JSON.stringify(testArr));