Skip to content

Instantly share code, notes, and snippets.

@jeremymouzin
Last active June 28, 2020 13:10
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/3fc90ab060378c2b259dfa7a9329b0eb to your computer and use it in GitHub Desktop.
Save jeremymouzin/3fc90ab060378c2b259dfa7a9329b0eb to your computer and use it in GitHub Desktop.
Challenge 4 du Challenge JavaScript 10 jours de Scrimba
// 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