JS排队问题

阅读 46

2022-02-19

  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)

0 0 举报