Created
September 18, 2017 13:26
-
-
Save DrinKaziu/195d35bc844814ece22d35301b1b2db6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ganavoj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| function keyDeleter(obj) { | |
| delete obj.foo; | |
| delete obj.bar; | |
| return obj | |
| } | |
| var sampleObj = { | |
| foo: 'foo', | |
| bar: 'bar', | |
| bizz: 'bizz', | |
| bang: 'bang' | |
| }; | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| (function testKeyDeleter() { | |
| var obj = keyDeleter({ | |
| foo: 'foo', | |
| bar: 'bar', | |
| bizz: 'bizz', | |
| bang: 'bang' | |
| }); | |
| if (typeof obj !== 'object') { | |
| console.error('ERROR: `keyDeleter` must be return an object'); | |
| return false | |
| } | |
| ['foo', 'bar'].forEach(function(key) { | |
| if (key in obj) { | |
| console.error('`keyDeleter` did not delete the key for ' + key); | |
| return false; | |
| } | |
| }); | |
| ['bizz', 'bang'].forEach(function(key) { | |
| if (!(key in obj && obj[key] === key)) { | |
| console.error('`keyDeleter` is deleting keys other than `foo` and `bar`'); | |
| return false; | |
| } | |
| }); | |
| console.log('SUCCESS: `updateObject` works correctly!'); | |
| })(); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">function keyDeleter(obj) { | |
| delete obj.foo; | |
| delete obj.bar; | |
| return obj | |
| } | |
| var sampleObj = { | |
| foo: 'foo', | |
| bar: 'bar', | |
| bizz: 'bizz', | |
| bang: 'bang' | |
| }; | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| (function testKeyDeleter() { | |
| var obj = keyDeleter({ | |
| foo: 'foo', | |
| bar: 'bar', | |
| bizz: 'bizz', | |
| bang: 'bang' | |
| }); | |
| if (typeof obj !== 'object') { | |
| console.error('ERROR: `keyDeleter` must be return an object'); | |
| return false | |
| } | |
| ['foo', 'bar'].forEach(function(key) { | |
| if (key in obj) { | |
| console.error('`keyDeleter` did not delete the key for ' + key); | |
| return false; | |
| } | |
| }); | |
| ['bizz', 'bang'].forEach(function(key) { | |
| if (!(key in obj && obj[key] === key)) { | |
| console.error('`keyDeleter` is deleting keys other than `foo` and `bar`'); | |
| return false; | |
| } | |
| }); | |
| console.log('SUCCESS: `updateObject` works correctly!'); | |
| })();</script></body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment