---恢復內容開始---
.pop() 將數組末尾的元素移除 var removedFromMyArray=myArray.pop() 將myArray數組的最后一個元素移除並賦給removedFromMyArray
.shift 將數組第一個元素移除 var removedFromMyArray=myArray.shift() 將myArray數組的第一個元素移除並賦給removedFromMyArray
.push() 在數組末尾添加元素 .unshift() 在數組開頭添加元素 例:myArray.push(["paul",35]);
一個程序中有可能具有相同名稱的 局部 變量 和 全局 變量。在這種情況下,局部
變量將會優先於 全局
變量。
function queue(arr, item) {
// Your code here
arr.push(item);
return arr.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
寫一個函數 queue
,用一個數組arr
和一個數字item
作為參數。數字item
添加到數組的結尾,然后移出數組的第一個元素,最后隊列函數應該返回被刪除的元素。
return是一個好東西 return a<b;自動比較a和b的大小,然后返回布爾值
Math.random()從0到1中隨機抽取一個小數 包括0但是不包括1
---恢復內容結束---