Last active
June 28, 2020 13:10
-
-
Save jeremymouzin/3fc90ab060378c2b259dfa7a9329b0eb to your computer and use it in GitHub Desktop.
Challenge 4 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 arrayReplace(tableau, nombreARemplacer, nouvelleValeur) { | |
const resultat = []; | |
for(nombre of tableau) { | |
if (nombre === nombreARemplacer) { | |
resultat.push(nouvelleValeur); | |
} else { | |
resultat.push(nombre); | |
} | |
} | |
return resultat; | |
} | |
// Version avancée compacte | |
function arrayReplace(tableau, nombreARemplacer, nouvelleValeur) { | |
return tableau.map(nombre => nombre === nombreARemplacer ? nouvelleValeur : nombre); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment