Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created March 13, 2020 05:47
Show Gist options
  • Save jsmanifest/2b31b57925a01626b431bd62b184aeda to your computer and use it in GitHub Desktop.
Save jsmanifest/2b31b57925a01626b431bd62b184aeda 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 innerObj = obj[key]
const innerObjKeys = Object.keys(innerObj)
for (let innerIndex = 0; innerIndex < innerObjKeys.length; innerIndex++) {
const innerObjKey = innerObjKeys[innerIndex]
const innerObjKeyValue = innerObj[innerObjKey]
if (typeof innerObjKeyValue === 'number') {
innerObj[innerObjKey] = innerObj[innerObjKey] * 2
}
}
}
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