2022/12/24

2418. Sort the People

問題:排序名稱 解法:儲存到陣列排序輸出即可 JavaScript
/**
 * @param {string[]} names
 * @param {number[]} heights
 * @return {string[]}
 */
var sortPeople = function (names, heights) {
    let temp = [];
    names.forEach((v, i) => temp.push([v, heights[i]]))
    temp = temp.sort((a, b) => b[1] - a[1]);
    return temp.map(s => s[0]);
};