Skip to content

Instantly share code, notes, and snippets.

@fourcolors
Created June 21, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourcolors/f21bdfbede8acfdd3917b16e9bf138ad to your computer and use it in GitHub Desktop.
Save fourcolors/f21bdfbede8acfdd3917b16e9bf138ad to your computer and use it in GitHub Desktop.
sort problem
const sortedReference = [
'ITEM-1',
'ITEM-2',
'ITEM-3',
'ITEM-4',
'ITEM-5',
'ITEM-6',
'ITEM-7',
'ITEM-8',
'ITEM-9',
'ITEM-10',
]
const purchased = [
'ITEM-3',
'ITEM-1',
'ITEM-5',
'ITEM-10',
'ITEM-8',
]
const sorted = [...purchased].sort((a, b) => (
sortedReference.indexOf(a) - sortedReference.indexOf(b)
))
console.log(sorted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment