Created
March 13, 2020 05:49
-
-
Save jsmanifest/bd74449062dc21a757b17ee8840cc7fc 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