Freecodecamp: Desafío en fila: validación incorrecta

Creado en 24 jun. 2016  ·  3Comentarios  ·  Fuente: freeCodeCamp/freeCodeCamp

Nombre del desafío: hacer fila

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

descripcion del problema

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

Información del navegador

  • Nombre del navegador, versión: Chrome, 51.0.2704.84 (64 bits)
  • Sistema operativo: Ubuntu 14.04
  • Móvil, escritorio o tableta: escritorio

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 pantalla

screenshot114

Comentario más útil

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
}

Todos 3 comentarios

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.

¿Fue útil esta página
0 / 5 - 0 calificaciones