Created
June 29, 2020 13:55
-
-
Save jeremymouzin/a6fe9fc1a0b0147f67e6932fbdabe398 to your computer and use it in GitHub Desktop.
Challenge 5 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 caseInsensitivePalindrome(mot) { | |
// On met tout en minuscules pour rester insensible à la casse | |
mot = mot.toLowerCase(); | |
// On transforme la chaîne en tableau de caractères... | |
let palindrome = mot.split(''); | |
// ...pour pouvoir utiliser les méthodes des tableaux | |
// et ainsi "retourner" facilement le mot | |
palindrome = palindrome.reverse().join(''); | |
// On teste si le mot retourné est égal au mot | |
return mot === palindrome; | |
} | |
// Version avancée compacte | |
function caseInsensitivePalindrome(mot) { | |
return (mot = mot.toLowerCase()) === [...mot].reverse().join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment