Created
March 13, 2020 05:48
-
-
Save jsmanifest/96a7010fdb80dc72ec63bc4e0c0576ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doubleTheNums(obj) { | |
const keys = Object.keys(obj) | |
for (let index = 0; index < keys.length; index++) { | |
const key = keys[index] | |
const value = obj[key] | |
if (typeof value === 'number') { | |
obj[key] = obj[key] * 2 | |
} else if (value && typeof value === 'object') { | |
doubleTheNums(obj[key]) | |
} | |
} | |
return obj | |
} | |
const results = { | |
game1: { | |
lakers: 40, | |
celtics: 40, | |
overtime: { | |
lakers: 48, | |
celtics: 58, | |
}, | |
}, | |
game2: { | |
lakers: 40, | |
celtics: 21, | |
}, | |
game3: { | |
lakers: 12, | |
celtics: 29, | |
}, | |
} | |
console.log(doubleTheNums(results)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment