Skip to content

Instantly share code, notes, and snippets.

@gagsy
Created June 30, 2019 17:08
Show Gist options
  • Save gagsy/a4d1cf994f3c02cecf4f707d36830dc3 to your computer and use it in GitHub Desktop.
Save gagsy/a4d1cf994f3c02cecf4f707d36830dc3 to your computer and use it in GitHub Desktop.
import _ from 'underscore';
let ranks = [{name:'one',rank:1},{name:'two',rank:2}];
let getByRanks = (ranks)=>{
return _.sortBy(_pluck(ranks,'rank'), function(num) {
return num;
})
};
let getRankAverage = (ranks)=>{
return _.reduce(_.pluck(ranks,'rank'), function(memo, num) {
return memo + num;
}, 0) / (arr.length === 0 ? 1 : arr.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment