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