theonlychase
5/7/2019 - 2:17 AM

Array.sort()

// 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"]