https://www.freecodecamp.com/challenges/stand-in-line
Cuando se usa la función push and shift, la validación "nextInLine ([5,6,7,8,9], 1) debería devolver 5" muestra que estoy equivocado.
Sin embargo, al insertar manualmente la matriz '[5,6,7,8,9]' a testArr, y el argumento '1' al llamar a la función, devuelve '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));
Deberías usar el parámetro en tu función, no testArr
Tu codigo:
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
Código correcto:
function nextInLine(arr, item) {
arr.push(item);
return arr.shift(); // Change this line
}
Gracias.
Comentario más útil
Tu codigo:
Código correcto: