Last active
April 19, 2023 11:47
-
-
Save ValentaTomas/a7297751461854686483dd7bad902cee to your computer and use it in GitHub Desktop.
Sort by an order given in an array
This file contains 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
export function sortByOrder<O, I>(order: O[], getID: (item: I) => O) { | |
return (a: I, b: I) => { | |
const aID = getID(a) | |
const bID = getID(b) | |
return order.indexOf(aID) - order.indexOf(bID) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment