Created
July 27, 2017 14:24
-
-
Save pawel-dubiel/eb19b94d0b351f086aeecb7aa5433452 to your computer and use it in GitHub Desktop.
test
This file contains 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
//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