Ranking System
JavaScript
function rankings(arr) {
var originalArr = [...arr];
var sortedArray = arr.concat().sort(function (a, b) { return b - a; });
var rankings = [];
let len = arr.length;
for (let i = 0; i < len; i++) {
rankings[originalArr.indexOf(sortedArray[i])] = i + 1;
}
return rankings;
}
Python
def rankings(arr):
sortedArray = sorted(arr, reverse=True)
length = len(arr)
rankings = [None] * length
for i in range(length):
rankings[arr.index(sortedArray[i])] = i + 1
return rankings
- javascript (Private)
- python (Private)
- 6-kyu (Private)
- codewars (Private)
- answer (Private)