상대 순위 - I

4081 단어 leetcodejavascript
/**
 * @param {number[]} score
 * @return {string[]}
 */
var findRelativeRanks = function(score) {
    const sortedArray = [...score].sort((a,b) => b-a);
  let count = 1;
  let obj = {};
  for (let i = 0; i < sortedArray.length; i++) {
    obj[sortedArray[i]] = getValue(count);
    count++;
  }

    for(let i=0; i<score.length; i++){
        score[i] = obj[score[i]]?.toString()
    }
    return score
};

const getValue = (count) =>{

    switch(count){
        case 1:
            return "Gold Medal";
        case 2:
            return "Silver Medal";   
        case 3:
            return "Bronze Medal"
        default:
            return count;
    }

}

좋은 웹페이지 즐겨찾기