Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Created January 19, 2018 00:10
Show Gist options
  • Save NimaBoscarino/2b6170f92e2947a6f1661f7436724d8c to your computer and use it in GitHub Desktop.
Save NimaBoscarino/2b6170f92e2947a6f1661f7436724d8c to your computer and use it in GitHub Desktop.
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