-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
41 lines (30 loc) · 1.06 KB
/
kata.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
// 42: array - `Array.prototype.keys`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Array.prototype.keys` returns an iterator for all keys in the array', () => {
it('`keys()` returns an iterator', function() {
const arr = ['a', 'b'];
const iterator = arr.keys();
assert.deepEqual(iterator.next(), {value: 0, done: false});
assert.deepEqual(iterator.next(), {value: void 0, done: true});
});
it('gets all keys', function() {
const arr = [1, 2];
const keys = Array.from(arr.keys());
assert.deepEqual(keys, [0, 1, 2]);
});
it('empty array contains no keys', function() {
const arr = ['empty me'];
const keys = [...arr.keys()];
assert.equal(keys.length, 0);
});
it('a sparse array without real values has keys though', function() {
const arr = [,,];
const keys = [...arr.___()];
assert.deepEqual(keys, [0, 1]);
});
it('also includes holes in sparse arrays', function() {
const arr = ['a', , 'c'];
const keys = arr.keys;
assert.deepEqual(keys, [0, 1, 2]);
});
});