Skip to content

Instantly share code, notes, and snippets.

@ValentaTomas
Last active April 19, 2023 11:47
Show Gist options
  • Save ValentaTomas/a7297751461854686483dd7bad902cee to your computer and use it in GitHub Desktop.
Save ValentaTomas/a7297751461854686483dd7bad902cee to your computer and use it in GitHub Desktop.
Sort by an order given in an array
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