0
点赞
收藏
分享

微信扫一扫

JS排队问题

Alex富贵 2022-02-19 阅读 45
javascript
  1. The element removed can be returned directly using return arr.shift();
  2. console.log() 方法用于在控制台输出信息 注意:它并不是返回值的语法
  3. pop-push 末尾进出
  4. shift-unshift开头进出

function nextInLine(arr, item) {
  // 只修改这一行下面的代码
  arr.push(item); 
  return arr.shift();
  // 只修改这一行上面的代码
}

// 设置
const testArr = [1, 2, 3, 4, 5];

// 显示代码
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
举报

相关推荐

0 条评论