Last active
September 21, 2018 12:54
-
-
Save AyoAlfonso/10a9ab9c36a4d80c168444a9a69c3ed3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let array = [{ | |
name: "John", | |
ranking: 5 | |
}, { | |
name: "Sam", | |
ranking: 4 | |
}, { | |
name: "Timi", | |
ranking: 1 | |
}, { | |
name: "Devon", | |
ranking: 7 | |
}, { | |
name: "Ismaila", | |
ranking: 10 | |
}, ] | |
const arrangeByRank = (data) => { | |
data.sort(function(a, b) { | |
return a.ranking - b.ranking; | |
}); | |
return data | |
} | |
console.log(arrangeByRank(array)) | |
/* expected output: [ { name: 'Timi', ranking: 1 }, | |
{ name: 'Sam', ranking: 4 }, | |
{ name: 'John', ranking: 5 }, | |
{ name: 'Devon', ranking: 7 }, | |
{ name: 'Ismaila', ranking: 10 } ] | |
*/ | |
const rankingAvr = (data) => { | |
let sum = 0; | |
data.map(person => { | |
sum = person.ranking + sum | |
}) | |
return sum / data.length | |
} | |
console.log(rankingAvr(array)) | |
/* expected output: | |
5.4 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment