Guest User

Untitled

a guest
Oct 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function updateObject(obj) {
  2. // your code here
  3. obj.foo = 'foo';
  4. obj.bar = 'bar';
  5. obj.bizz = 'bizz';
  6. obj.bang = 'bang';
  7. return obj;
  8. }
  9.  
  10.  
  11.  
  12. /* From here down, you are not expected to
  13. understand.... for now :)
  14.  
  15.  
  16. Nothing to see here!
  17.  
  18. */
  19.  
  20. (function testUpdateObject() {
  21. var oldObj = {
  22. cats: 'cats',
  23. dogs: 'dogs',
  24. };
  25. var newObj = updateObject(oldObj);
  26. if (typeof newObj !== 'object') {
  27. console.error('ERROR: `createMyObject` must return an object');
  28. return false
  29. }
  30. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  31. if (!(key in newObj)) {
  32. console.error('ERROR: `' + key + '` not in object returned by `updateObject`');
  33. return false;
  34. }
  35. });
  36. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  37. if (newObj[key] !== key) {
  38. console.error('ERROR: `' + key + '` should be "' + key + '" but was ' + newObj[key]);
  39. return false;
  40. }
  41. });
  42. if (!(newObj.cats === 'cats' && newObj.dogs === 'dogs')) {
  43. console.error('ERROR: your function doesn\'t preserve existing key/value pairs');
  44. return false;
  45. }
  46. console.log('SUCCESS: `updateObject` works correctly!');
  47.  
  48. })();
Add Comment
Please, Sign In to add comment