Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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. */
- function checkMatchingLeaves(obj) {
- let val;
- let flag = true;
- const checkLeaves = (tree) => {
- Object.keys(tree).forEach((key) => { //* * make comments for each line
- if (val === undefined && typeof key !== 'object') {
- val = tree[key];
- return undefined;
- }
- if (typeof tree[key] === 'object') return checkLeaves(tree[key]);
- if (tree[key] !== val) {
- flag = false;
- return undefined;
- }
- });
- };
- checkLeaves(obj);
- return flag;
- }
Add Comment
Please, Sign In to add comment