Freecodecamp: 排队挑战 - 错误的验证

创建于 2016-06-24  ·  3评论  ·  资料来源: freeCodeCamp/freeCodeCamp

挑战名称:排队

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

问题描述

使用 push 和 shift 函数时,验证“nextInLine([5,6,7,8,9], 1) should return 5”表明我错了。
但是,当手动将数组 '[5,6,7,8,9]' 插入到 testArr 中,并在调用函数时将参数 '1' 插入时,它返回 '5'。

浏览器信息

  • 浏览器名称,版本:Chrome,51.0.2704.84(64 位)
  • 操作系统:Ubuntu 14.04
  • 手机、台式机或平板电脑:台式机

代码

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

截屏

screenshot114

最有用的评论

您的代码:

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
}

所有3条评论

您应该在函数中使用参数而不是 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
}

知道了谢谢。

此页面是否有帮助?
0 / 5 - 0 等级