Freecodecamp: Desafio de linha - validação errada

Criado em 24 jun. 2016  ·  3Comentários  ·  Fonte: freeCodeCamp/freeCodeCamp

Nome do desafio: Fique na fila

https://www.freecodecamp.com/challenges/stand-in-line

descrição do problema

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'.

Informação do navegador

  • Nome do navegador, versão: Chrome, 51.0.2704.84 (64 bits)
  • Sistema operacional: Ubuntu 14.04
  • Celular, desktop ou tablet: desktop

Código

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));

Captura de tela

screenshot114

Comentários muito úteis

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
}

Todos 3 comentários

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.

Esta página foi útil?
0 / 5 - 0 avaliações