-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
33 lines (23 loc) · 934 Bytes
/
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
// 32: array - `Array.prototype.find` (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Array.prototype.find` makes finding items in arrays easier', () => {
it('takes a compare function', function() {
const found = [false, true].find( ( element) => element === true );
assert.equal(found, true);
});
it('returns the first value found', function() {
const found = [0, 1, 2].find(item => item > 1);
assert.equal(found, 2);
});
it('returns `undefined` when nothing was found', function() {
const found = [1, 3].find(item => item === 2);
assert.equal(found, void 0);
});
it('combined with destructuring complex compares become short', function() {
const bob = {name: 'Bob'};
const alice = {name: 'Alice'};
const found = [bob, alice].find(
({name:{length}}) => length === alice.name.length );
assert.equal(found, alice);
});
});