Guest User

Untitled

a guest
Nov 12th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // 21: spread - with-strings
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('spread with strings', () => {
  6.  
  7. it('simply spread each char of a string', function() {
  8. const [a,b] = [...'ab'];
  9. assert.equal(a, 'a');
  10. assert.equal(b, 'b');
  11. });
  12.  
  13. it('extracts each array item', function() {
  14. const [a,b,c] = [ ...'12'];
  15. assert.equal(a, 1);
  16. assert.equal(b, 2);
  17. });
  18.  
  19. it('works anywhere inside an array (must not be last)', function() {
  20. const letters = ['a', ...'bcd', 'e', 'f'];
  21. assert.equal(letters.length, 6);
  22. });
  23.  
  24. it('dont confuse with the rest operator', function() {
  25. const [...rest] = [...'1234', ...'5'];//used before a string, will spread the string into an array
  26. assert.deepEqual(rest, [1, 2, 3, 4, 5]);
  27. });
  28.  
  29. it('passed as function parameter', function() {
  30. const max = Math.max(...'12345');
  31. assert.deepEqual(max, 5);
  32. });
  33.  
  34. });
Add Comment
Please, Sign In to add comment