Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. 'use strict'
  2.  
  3. /*
  4. * Create a `get` function that takes a key and return the corresponding value
  5. * in the sourceObject
  6. *
  7. * @notions Functions, Data-Structures, Get
  8. */
  9.  
  10. // Provided code :
  11. const sourceObject = {
  12. num: 42,
  13. bool: true,
  14. str: 'some text',
  15. log: console.log,
  16. }
  17.  
  18.  
  19.  
  20. // Your code :
  21. function get(key) {
  22. return sourceObject[key];
  23. }
  24.  
  25.  
  26. //* Begin of tests
  27. const assert = require('assert')
  28.  
  29. assert.strictEqual(typeof get, 'function')
  30. assert.strictEqual(get('num'), 42)
  31. assert.strictEqual(get('bool'), true)
  32. assert.strictEqual(get('str'), 'some text')
  33. assert.strictEqual(get('log'), console.log)
  34. assert.strictEqual(get('noexist'), undefined)
  35. // End of tests */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement