Created
November 17, 2023 23:45
-
-
Save mburbea/9ca7412be0887847f69e967c3eba76f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pctRankArray(array:number[]){ | |
const normalMap = [...new Set(array)] | |
.sort((x, y) => x - y) | |
.reduce((map, val, ix, arr) => { | |
map.set(val, ix / (arr.length - 1)); | |
return map; | |
}, new Map<number, number>()); | |
return array.map(v => normalMap.get(v)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment