https://www.freecodecamp.com/challenges/stand-in-line
プッシュおよびシフト関数を使用する場合、「nextInLine([5,6,7,8,9]、1)は5を返す必要があります」という検証は、私が間違っていることを示しています。
ただし、配列「[5,6,7,8,9]」をtestArrに手動で挿入し、関数を呼び出すときに引数「1」を挿入すると、「5」が返されます。
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
var testArr = [5,6,7,8,9];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
testArrではなく関数でパラメーターを使用する必要があります
あなたのコード:
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
正しいコード:
function nextInLine(arr, item) {
arr.push(item);
return arr.shift(); // Change this line
}
了解、ありがとう。
最も参考になるコメント
あなたのコード:
正しいコード: