https://www.freecodecamp.com/challenges/stand-in-line
Ao usar a função push e shift, a validação "nextInLine ([5,6,7,8,9], 1) deve retornar 5" mostra que estou errado.
No entanto, ao inserir manualmente o array '[5,6,7,8,9]' para testArr e o argumento '1' ao chamar a função, ele retorna '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));
Você deve usar o parâmetro em sua função, não testArr
Seu código:
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
Código correto:
function nextInLine(arr, item) {
arr.push(item);
return arr.shift(); // Change this line
}
Entendi, obrigado.
Comentários muito úteis
Seu código:
Código correto: