Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. ```javascript
  2. function goodKeys(obj, callback) {
  3. let array = [];
  4. // loop through each property obj
  5. for (let property in obj) {
  6. // if the return value of the callback equals true
  7. if (callback(obj[property]) === true) {
  8. // then push key to array
  9. array.push(property);
  10. }
  11. }
  12. return array;
  13. }
  14. // Uncomment these to check your work!
  15. const sunny = { mac: 'priest', dennis: 'calculator', charlie: 'birdlaw', dee: 'bird', frank: 'warthog' };
  16. function startsWithBird(str) { return str.slice(0, 4).toLowerCase() === 'bird'; };
  17. console.log(goodKeys(sunny, startsWithBird)); // should log: ['charlie', 'dee']
  18. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement