It is fun to chain methods of array in JavaScript.
/**
* @param {number[]} score
* @return {string[]}
*/
var findRelativeRanks = function (score) {
return score
.map((v, i) => [v, i])
.toSorted((a, b) => b[0] - a[0])
.map(([v, i], j) => [v, i, j])
.toSorted((a, b) => a[1] - b[1])
.map(([v, i, j]) =>
j === 0
? "Gold Medal"
: j === 1
? "Silver Medal"
: j === 2
? "Bronze Medal"
: `${j + 1}`
);
};