Skip to content

Instantly share code, notes, and snippets.

@linux08
Created October 9, 2018 00:46
Show Gist options
  • Save linux08/c45cf459805bc8d8542389cf9ac6a6ec to your computer and use it in GitHub Desktop.
Save linux08/c45cf459805bc8d8542389cf9ac6a6ec to your computer and use it in GitHub Desktop.
//orders the item in an array of object by their ranking in ascending order
function sort(data) {
return data.sort((a, b) => {
return a.ranking - b.ranking;
});
};
//find the average ranking present in an array of object;
function average(data) {
return (
data.reduce((prev, curr) => {
return prev + curr.ranking;
}, 0) / data.length
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment