Guest User

Untitled

a guest
Dec 17th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. /* Write a function called checkMatchingLeaves that takes in an object, and return true if every property on the object is the same, otherwise, return false. */
  2.  
  3. function checkMatchingLeaves(obj) {
  4. let val;
  5. let flag = true;
  6. const checkLeaves = (tree) => {
  7. Object.keys(tree).forEach((key) => { //* * make comments for each line
  8. if (val === undefined && typeof key !== 'object') {
  9. val = tree[key];
  10. return undefined;
  11. }
  12. if (typeof tree[key] === 'object') return checkLeaves(tree[key]);
  13. if (tree[key] !== val) {
  14. flag = false;
  15. return undefined;
  16. }
  17. });
  18. };
  19. checkLeaves(obj);
  20. return flag;
  21. }
Add Comment
Please, Sign In to add comment