Last active
June 28, 2020 06:05
-
-
Save jeremymouzin/b522ac435d9c40318cd0c49293c857d7 to your computer and use it in GitHub Desktop.
Challenge 2 du Challenge JavaScript 10 jours de Scrimba
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
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
cool le map. on s'en sert souvent mais j'ai pas encore l'habitude d'y penser