Created
July 2, 2020 21:14
-
-
Save jeremymouzin/563d54edb00e928a8d51851c27394dec to your computer and use it in GitHub Desktop.
Challenge 8 du Challenge JavaScript 10 jours de Scrimba
This file contains hidden or 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 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