Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created March 13, 2020 05:48
Show Gist options
  • Save jsmanifest/96a7010fdb80dc72ec63bc4e0c0576ab to your computer and use it in GitHub Desktop.
Save jsmanifest/96a7010fdb80dc72ec63bc4e0c0576ab to your computer and use it in GitHub Desktop.
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