Created
September 21, 2022 13:25
-
-
Save beelarr/5df417632b0b24392624a80c14bdeb95 to your computer and use it in GitHub Desktop.
Sort based on array of sorted values
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
const ORDERED_LIST = ['firstSortItem', 'secondSortItem', 'thirdSortItem'] | |
const sorted = [...itemsToSort]; | |
sorted.sort( | |
(a, b) => | |
ORDERED_LIST.findIndex( | |
(orderedAttribute) => orderedAttribute === a.orderedAttribute, | |
) - | |
ORDERED_LIST.findIndex( | |
(orderedAttribute) => orderedAttribute === b.orderedAttribute, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://replit.com/@_beelarr_/Sort-by-List