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
}
حسنًا ، شكرًا.
التعليق الأكثر فائدة
الكود الخاص بك:
الكود الصحيح: