Skip to content

Instantly share code, notes, and snippets.

@beelarr
Created September 21, 2022 13:25
Show Gist options
  • Save beelarr/5df417632b0b24392624a80c14bdeb95 to your computer and use it in GitHub Desktop.
Save beelarr/5df417632b0b24392624a80c14bdeb95 to your computer and use it in GitHub Desktop.
Sort based on array of sorted values
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,
),
);
@beelarr
Copy link
Author

beelarr commented Sep 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment