Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```javascript
- function goodKeys(obj, callback) {
- let array = [];
- // loop through each property obj
- for (let property in obj) {
- // if the return value of the callback equals true
- if (callback(obj[property]) === true) {
- // then push key to array
- array.push(property);
- }
- }
- return array;
- }
- // Uncomment these to check your work!
- const sunny = { mac: 'priest', dennis: 'calculator', charlie: 'birdlaw', dee: 'bird', frank: 'warthog' };
- function startsWithBird(str) { return str.slice(0, 4).toLowerCase() === 'bird'; };
- console.log(goodKeys(sunny, startsWithBird)); // should log: ['charlie', 'dee']
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement