-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
39 lines (33 loc) · 1.08 KB
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 20: spread - with-arrays (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('spread with arrays', () => {
it('extracts each array item', function() {
const [a, b] = [...[1, 2]];
assert.equal(a, 1);
assert.equal(b, 2);
});
it('in combination with rest', function() {
const [a, b, ...rest] = [...[1, 2, 3, 4, 5]];
assert.equal(a, 1);
assert.equal(b, 2);
assert.deepEqual(rest, [3, 4, 5]);
});
it('spreading into the rest', function() {
const [...rest] = [...[1, 2, 3, 4, 5]];
assert.deepEqual(rest, [1, 2, 3, 4, 5]);
});
describe('used as function parameter', () => {
it('prefix with `...` to spread as function params', function() {
const magicNumbers = [1, 2];
const fn = (magicA, magicB) => {
assert.deepEqual(magicNumbers[0], magicA);
assert.deepEqual(magicNumbers[1], magicB);
};
fn(...magicNumbers);
});
it('pass an array of numbers to Math.max()', function() {
const max = Math.max(...[23, 0, 42, 41]);
assert.equal(max, 42);
});
});
});