daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const sampleObj = {
  2.   foo: 'foo',
  3.   bar: 'bar',
  4.   bizz: 'bizz',
  5.   bang: 'bang',
  6. };
  7.  
  8. function keyDeleter(obj) {
  9.   delete obj.foo;
  10.   delete obj.bar;
  11.   return obj;
  12.  
  13.   // your code here
  14. }
  15.  
  16. /* From here down, you are not expected to
  17.    understand.... for now :)  
  18.    
  19.    
  20.    Nothing to see here!
  21.    
  22. */
  23.  
  24. (function testKeyDeleter() {
  25.   var obj = keyDeleter({
  26.     foo: 'foo',
  27.     bar: 'bar',
  28.     bizz: 'bizz',
  29.     bang: 'bang',
  30.   });
  31.  
  32.   if (typeof obj !== 'object') {
  33.     console.error('ERROR: `keyDeleter` must be return an object');
  34.     return false;
  35.   }
  36.   ['foo', 'bar'].forEach(function(key) {
  37.     if (key in obj) {
  38.       console.error('`keyDeleter` did not delete the key for ' + key);
  39.       return false;
  40.     }
  41.   });
  42.   ['bizz', 'bang'].forEach(function(key) {
  43.     if (!(key in obj && obj[key] === key)) {
  44.       console.error('`keyDeleter` is deleting keys other than `foo` and `bar`');
  45.       return false;
  46.     }
  47.   });
  48.   console.log('SUCCESS: `keyDeleter` works correctly!');
  49. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top