/*
* @lc app=leetcode.cn id=1331 lang=typescript
*
* [1331] 数组序号转换
*/
// @lc code=start
function arrayRankTransform(arr: number[]): number[] {}
// @lc code=end
function arrayRankTransform(arr: number[]): number[] {
const map = new Map([...new Set(arr)].sort((a, b) => a - b).map((num, i) => [num, i]))
return arr.map(num => map.get(num)! + 1)
}
test.each([
{ input: { arr: [40, 10, 20, 30] }, output: [4, 1, 2, 3] },
{ input: { arr: [100, 100, 100] }, output: [1, 1, 1] },
{ input: { arr: [37, 12, 28, 9, 100, 56, 80, 5, 12] }, output: [5, 3, 4, 2, 8, 6, 7, 1, 3] },
])('input: arr = $input.arr', ({ input: { arr }, output }) => {
expect(arrayRankTransform(arr)).toEqual(output)
})