-
Notifications
You must be signed in to change notification settings - Fork 0
/
43_array_values.js
41 lines (29 loc) · 1.09 KB
/
43_array_values.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
40
41
// 43: array - `Array.prototype.values`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Array.prototype.values` returns an iterator for all values in the array', () => {
it('`values()` returns an iterator', function() {
const arr = [];
const iterator = arr.values();
assert.deepEqual(iterator.next(), {value: void 0, done: true});
});
it('use iterator to drop first key', function() {
const arr = ['keys', 'values', 'entries'];
const iterator = arr.values();
iterator.next();
assert.deepEqual([...iterator], ['values', 'entries']);
});
it('empty array contains no values', function() {
const arr = [...[...[...[]]]];
const values = [...arr.values()];
assert.equal(values.length, 0);
});
it('a sparse array without real values has values though', function() {
const arr = [,,];
const keys = [...arr.values()];
assert.deepEqual(keys, [void 0, void 0]);
});
it('also includes holes in sparse arrays', function() {
const arr = ['a',,'c'];
assert.deepEqual([...arr.values()], ['a', void 0, 'c']);
});
});