Created
February 14, 2024 11:22
-
-
Save dominique-mueller/8d2d38a2680df5cfa84aa30a8a80a3cd to your computer and use it in GitHub Desktop.
sort-to-top.ts
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
/** | |
* 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