Guest User

Untitled

a guest
Nov 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // 12: destructuring - object
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('Destructure objects', () => {
  6. it('by surrounding the left-hand variable with `{}`', () => {
  7. const {x} = {x: 1};
  8. assert.equal(x, 1);
  9. });
  10. describe('nested', () => {
  11. it('multiple objects', () => {
  12. const magic = {first: 23, second: 42};
  13. const {magic: second} = {magic: 42};
  14. assert.equal(second, 42);
  15. });
  16. it('object and array', () => {
  17. const {z:[,x]} = {z: [23, 42]};//added , to set x = to second item in array
  18. assert.equal(x, 42);
  19. });
  20. it('array and object', () => {
  21. const [,[{env, lang}]] = [null, [{env: 'browser', lang: 'ES6'}]];
  22. assert.equal(lang, 'ES6');
  23. });
  24. });
  25. describe('interesting', () => {
  26. it('missing refs become undefined', () => {
  27. const {z} = {x: 1};
  28. assert.equal(z, void 0);
  29. });
  30. it('destructure from builtins (string)', () => {
  31. const {substr} = '1';
  32. assert.equal(substr, String.prototype.substr);
  33. });
  34. });
  35. });
Add Comment
Please, Sign In to add comment