FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.

Home Page:https://fcc.asia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

结果是shift不是一个函数?

chenyi369 opened this issue · comments

Challenge Stand in Line has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function queue(arr, item) {
  arr = arr.push(item);// 请把你的代码写在这里
  var aA = arr.shift()
  return aA;  // 请修改这一行
}

// 初始化测试数据
var testArr = [1,2,3,4,5];

// 控制台输出
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // 你可以修改这一行来测试你的代码
console.log("After: " + JSON.stringify(testArr));

function queue(arr, item) {
// 请把你的代码写在这里
arr.splice(arr.length,0,item); //用splice 可解决
return arr.shift(); // 请修改这一行
}