Skip to content

Instantly share code, notes, and snippets.

@jeremymouzin
Last active June 28, 2020 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremymouzin/b522ac435d9c40318cd0c49293c857d7 to your computer and use it in GitHub Desktop.
Save jeremymouzin/b522ac435d9c40318cd0c49293c857d7 to your computer and use it in GitHub Desktop.
Challenge 2 du Challenge JavaScript 10 jours de Scrimba
// Version lisible pour débutants
function allLongestStrings(tableauDeChaines) {
let longueurMax = 0;
for (chaine of tableauDeChaines) {
if (longueurMax < chaine.length) {
longueurMax = chaine.length;
}
}
let plusLonguesChaines = [];
for (chaine of tableauDeChaines) {
if (chaine.length === longueurMax) {
plusLonguesChaines.push(chaine);
}
}
return plusLonguesChaines;
}
// Version avancée compacte
function allLongestStrings(tableauDeChaines) {
const longueurMax = Math.max(...tableauDeChaines.map(chaine => chaine.length));
return tableauDeChaines.filter(chaine => chaine.length === longueurMax);
}
@newtomsoft
Copy link

cool le map. on s'en sert souvent mais j'ai pas encore l'habitude d'y penser

@jeremymouzin
Copy link
Author

cool le map. on s'en sert souvent mais j'ai pas encore l'habitude d'y penser

Oui c'est très pratique 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment