存稿 hhhh~
要求:
Add the number to the end of the array, then remove the first element of the array.
The nextInLine function should then return the element that was removed.
nextInLine([], 5)
should return a number.
nextInLine([], 1)
should return
1
nextInLine([2], 1)
should return
2
nextInLine([5,6,7,8,9], 1)
should return
5
After
nextInLine(testArr, 10)
,
testArr[4]
should be
10
代码实现
function nextInLine(arr, item) {
// 将item插到arr数组的尾巴
arr.push(item);
//移除数组的第一项,并且最后返回移除项
item=arr.shift(arr);
return item;
}
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));