const words = ["Beau", "Balle", "Ange", "Ananas", "Reduce","Action"];
Ecrire la fonction donnant pour chaque première lettre les mots !
" B => Beau,Balle"
" A => Ange,Ananas,Action"
" R => Reduce"
const words = ["Beau", "Balle", "Ange",
"Ananas", "Reduce","Action"];
const alphabetical = words.reduce((a, x) => {
if(!a[x[0]]) a[x[0]] = [];
a[x[0]].push(x);
return a; }, {});
Object.keys(alphabetical).forEach(function (key) {
console.log(` ${key} => ${alphabetical[key]}`);
});
console.log(alphabetical);