Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // 42: array - `Array.prototype.keys`
  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.keys` returns an iterator for all keys in the array', () => {
  6. it('`keys()` returns an iterator', function() {
  7. const arr = ['a'];
  8. const iterator = arr.keys();
  9. assert.deepEqual(iterator.next(), {value: 0, done: false});
  10. assert.deepEqual(iterator.next(), {value: void 0, done: true});
  11. });
  12. it('gets all keys', function() {
  13. const arr = ['a', 'b', 'c'];
  14. const keys = Array.from(arr.keys());
  15. assert.deepEqual(keys, [0, 1, 2]);
  16. });
  17. it('empty array contains no keys', function() {
  18. const arr = [];
  19. const keys = [...arr.keys()];
  20. assert.equal(keys.length, 0);
  21. });
  22. it('a sparse array without real values has keys though', function() {
  23. const arr = [,,];
  24. const keys = [...arr.keys()];
  25. assert.deepEqual(keys, [0, 1]);
  26. });
  27. it('also includes holes in sparse arrays', function() {
  28. const arr = ['a', , 'c'];
  29. const keys = Array.from(arr.keys());
  30. assert.deepEqual(keys, [0, 1, 2]);
  31. });
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement