Skip to content

Instantly share code, notes, and snippets.

@theonlychase theonlychase/sort
Created May 7, 2019

Embed
What would you like to do?
// Sort words by a given String
const sortByString = (arr, str) => arr.sort(([a], [b]) => str.indexOf(a) - str.indexOf(b)); // I guess the [a] [b] gives you the first letter of the value
sortByString(["apple", "banana", "cherry", "date"], "dbca") // "date", "banana", "cherry", "apple"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.