Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pawel-dubiel/eb19b94d0b351f086aeecb7aa5433452 to your computer and use it in GitHub Desktop.
Save pawel-dubiel/eb19b94d0b351f086aeecb7aa5433452 to your computer and use it in GitHub Desktop.
test
//use script not recommended in es6 modules
export {average, sort_by_ranking_desc};
let items = [],max_test_items=10;
for ( let i=0;i<max_test_items;i++) {
items[i] = { name: "foo", ranking: Math.random() };
}
let sort_by_ranking_desc = (a, b) => (b.ranking-a.ranking );
let average = (arrobj) => {
return arrobj.reduce((a, b) => ({ranking: a.ranking + b.ranking})).ranking/arrobj.length;
} ;
//display
console.log(average(items));
console.log(items.sort(sort_by_ranking_desc));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment