题目:
返回一个数组被截断n个元素后还盈余的元素,从索引0最先截断。
解答:
function slasher(arr, howMany) {
// it doesn't always pay to be first
var arrLength = arr.length;
var spliceLength = arrLength - howMany;
var spliceArr;
spliceArr = arr.splice(howMany, spliceLength);
return spliceArr;
}
slasher([1, 2, 3], 2);