Created
June 21, 2017 00:51
-
-
Save fourcolors/f21bdfbede8acfdd3917b16e9bf138ad to your computer and use it in GitHub Desktop.
sort problem
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 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