Skip to content

Instantly share code, notes, and snippets.

@mburbea
Created November 17, 2023 23:45
Show Gist options
  • Save mburbea/9ca7412be0887847f69e967c3eba76f7 to your computer and use it in GitHub Desktop.
Save mburbea/9ca7412be0887847f69e967c3eba76f7 to your computer and use it in GitHub Desktop.
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