Created
July 4, 2019 07:04
-
-
Save goodguy000/bf7499666846ebacda92211a802bacbe to your computer and use it in GitHub Desktop.
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
const charsers = [ | |
{ name: 'Nodejs', ranking: 7}, | |
{ name: 'Reactjs', ranking: 7.5}, | |
{ name: 'Vuejs', ranking: 6}, | |
{ name: 'MongoDB', ranking: 7}, | |
{ name: 'GraphQL', ranking: 7} | |
]; | |
function order(list, orderType) { | |
if (orderType === 'desc') { | |
return list.sort((a, b) => a.ranking < b.ranking ? 1 : -1); | |
} | |
return list.sort((a, b) => a.ranking > b.ranking ? 1: -1); | |
} | |
function getAverage(list, propType) { | |
const sum = list.map(item => item[propType]).reduce((prev, curr) => prev + curr, 0); | |
return sum / list.length; | |
} | |
const result = order(charsers, 'asc'); | |
const avarage = getAverage(charsers, 'ranking'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment