Guest User

Untitled

a guest
Jul 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // 21: spread - with-strings
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3.  
  4. describe('spread with strings', () => {
  5.  
  6. it('simply spread each char of a string', function() {
  7. //Another case of a and b being switched
  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. //Use a leading comma to skip over the 'Q' and '...' to break up '12'
  15. const [,a,b] = ['Q', ...'12'];
  16. assert.equal(a, 1);
  17. assert.equal(b, 2);
  18. });
  19.  
  20. it('works anywhere inside an array (must not be last)', function() {
  21. //Destructure 'bcd' so that all 3 characters are counted separately
  22. const letters = ['a', ...'bcd', 'e', 'f'];
  23. assert.equal(letters.length, 6);
  24. });
  25.  
  26. it('dont confuse with the rest operator', function() {
  27. //Use spread operator to break up '1234'
  28. const [...rest] = [...'1234', '5'];
  29. assert.deepEqual(rest, [1, 2, 3, 4, 5]);
  30. });
  31.  
  32. it('passed as function parameter', function() {
  33. //Cast 12345 to a string so that we can destructure it
  34. const max = Math.max(...'12345');
  35. assert.deepEqual(max, 5);
  36. });
  37.  
  38. });
Add Comment
Please, Sign In to add comment