配列から取り出した値をarr.shift()
から取得しようとしていますが、その値を返す必要があります。この?.shift()を使用して配列から取り除かれた値を返す方法
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr; // Change this line
}
// Test Setup
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));
'return arr.shift()'は1行で行います。あなたの現在のコードでは、 '.shift()'の結果を変数に格納してから、変数 –
を返す必要があります。関数から返すか、配列に返しますか? –