Skip to content

Instantly share code, notes, and snippets.

@jeremymouzin
Created July 2, 2020 21:14
Show Gist options
  • Select an option

  • Save jeremymouzin/563d54edb00e928a8d51851c27394dec to your computer and use it in GitHub Desktop.

Select an option

Save jeremymouzin/563d54edb00e928a8d51851c27394dec to your computer and use it in GitHub Desktop.
Challenge 8 du Challenge JavaScript 10 jours de Scrimba
// Version lisible pour les débutants
// Gère les espaces dans chaine
function firstDigit(chaine) {
for (caractere of chaine) {
if ("0123456789".includes(caractere)) {
return caractere;
}
}
}
// Version avancée compacte via une RegExp
function firstDigit(chaine) {
return (resultat = /\d{1}/.exec(chaine)) ? resultat[0] : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment