- Stand in Line | Free Code Camp
- freecodecamp-HTML5 and CSS3-第一课
- Review-The most important skill
- ??Drop it | Free Code Camp
- Day07 JavaScript(Algorithm)
- Hooks 二三事 (1) | 十分钟快速入门 React Ho
- Review-The Key To learning fast
- ??Binary Agents | Free Code Camp
- Profile Lookup | Free Code Camp
- Counting Cards | Free Code Camp
Write a function nextInLine which takes an array (arr) and a number (item) 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.
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) {
// Your code here
arr.push(item);
item = arr.shift();
return item; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10), testArr[4]); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
网友评论