Skip to content

Instantly share code, notes, and snippets.

@dominique-mueller
Created February 14, 2024 11:22
Show Gist options
  • Save dominique-mueller/8d2d38a2680df5cfa84aa30a8a80a3cd to your computer and use it in GitHub Desktop.
Save dominique-mueller/8d2d38a2680df5cfa84aa30a8a80a3cd to your computer and use it in GitHub Desktop.
sort-to-top.ts
/**
* Sort one value to the top
*/
export const sortToTop = <T>(list: Array<T>, matchFn: (item: T) => boolean): Array<T> => {
return list.toSorted((listItemA, listItemB) => {
return matchFn(listItemA) ? -1 : matchFn(listItemB) ? 0 : 1;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment