I'm new to JavaScript and currently working on a task involving queues. Here is the task description:
Create a function called nextInLine that takes an array (arr) and a number (item) as parameters. The function should add the number to the end of the array, then remove the first element of the array. Finally, the nextInLine function should return the element that was removed.
function nextInLine(arr, item) {
// Write your code here
return item; // Modify this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Adjust this line for testing
console.log("After: " + JSON.stringify(testArr));
Expected results:
nextInLine([], 1)
should return 1nextInLine([2], 1)
should return 2nextInLine([5,6,7,8,9], 1)
should return 5- After
nextInLine(testArr, 10)
,testArr[4]
should be 10