Array.prototype.slice()相同:
```js
const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
console.log(a, b); // 1, 2
console.log(arr); // [3, 4, 5, 7]
```
变量a与b分别获取了数组的前两个元素的值。之后,因为rest操作符的存在,arr获取了原数组剩余的元素的值,并构成了一个新的数组。
rest操作只能对数组列表最后的元素起作用。这意味着你不能使用rest操作符来截取原数组中间元素的子数组。
rest操作符来进行一个Array.prototype.slice相同的操作。使得arr是原数组source除开前两个元素的子数组。
arr应该为[3,4,5,6,7,8,9,10]
testString: assert(arr.every((v, i) => v === i + 3) && arr.length === 8);
- text: 没有使用Array.slice()。
testString: getUserInput => assert(!getUserInput('index').match(/slice/g));
- text: 使用了解构赋值。
testString: assert(code.replace(/\s/g, '').match(/\[(([_$a-z]\w*)?,){1,}\.\.\.arr\]=list/i));
```