Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created January 28, 2014 05:59
Show Gist options
  • Select an option

  • Save zhuangya/8662908 to your computer and use it in GitHub Desktop.

Select an option

Save zhuangya/8662908 to your computer and use it in GitHub Desktop.
var temperatureHistory = [{
State: 'Florida',
Temperature: 83,
},
{
State: 'Florida',
Temperature: 82,
},
{
State: 'Florida',
Temperature: 79,
},
{
State: 'Nevada',
Temperature: 96,
},
{
State: 'Nevada',
Temperature: 93,
}];
var max = temperatureHistory.reduce(function (topTemp, history) {
if (history.Temperature > topTemp[history.State] || -99999) {
topTemp[history.State] = history.Temperature;
}
return topTemp;
}, {});
console.log(max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment