I need to create a function indexWords() that takes an array as parameter and return an object with the first letter of the words as key and each keys list all of the words that start with this letter.
Here an exemple because my english is really bad lol:
indexWords(["apple", "car", "cat"]) // output: {a: ["apple"], c: ["car", "cat"]}
so I started to get an array with the first letter and remove duplicates letter by doing like so:
indexWords(arr) {
let firstLetters = [... new Set(arr.map(x => x[0]))]
}
But then I need to filter the given arr and create a new mapped array for each values that have the same first letter. Basically I should check if arr[i][0] === firstLetters[0], and then firstLetters[1] etc. But how to know how many index will be into firstLetters ? I'm lost...