Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // 32: array - `Array.prototype.find`
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('`Array.prototype.find` makes finding items in arrays easier', () => {
  6. it('takes a compare function', function() {
  7. const arr = [true]
  8. const found = arr.find( _ => true);
  9. assert.equal(found, true);
  10. });
  11. it('returns the first value found', function() {
  12. const found = [0, 1, 2].find(item => item > 1);
  13. assert.equal(found, 2);
  14. });
  15. it('returns `undefined` when nothing was found', function() {
  16. const found = [1, 5, 3].find(item => item === 2);
  17. assert.equal(found, void 0);
  18. });
  19. it('combined with destructuring complex compares become short', function() {
  20. const bob = {name: 'Bob'};
  21. const alice = {name: 'Alice'};
  22. const found = [bob, alice].find(({name}) => name === 'Alice');
  23. assert.equal(found, alice);
  24. });
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement