Created
January 19, 2018 00:10
-
-
Save NimaBoscarino/2b6170f92e2947a6f1661f7436724d8c 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
var obj = { | |
fo1 : 5, | |
fo2 : 3, | |
fo3 : 10, | |
fo4 : 3, | |
fo5 : 4, | |
fo6 : 4, | |
} | |
function getMax(object) { | |
var values = Object.keys(object).map(function(key) { | |
return { | |
value: object[key], | |
key: key | |
} | |
}) | |
const reducer = (accumulator, currentValue) => { | |
if (accumulator.value > currentValue.value) { | |
return accumulator | |
} | |
return currentValue | |
} | |
var max = values.reduce(reducer); | |
return max | |
} | |
console.log(getMax(obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment