Vérifier le spam
importance: 5
Écrire une fonction checkSpam(str)
qui retourne true
si str
contient ‘viagra’ ou ‘XXX’, sinon false
.
La fonction doit être sensible à la casse :
checkSpam
(
'buy ViAgRA now'
)
==
true
checkSpam
(
'free xxxxx'
)
==
true
checkSpam
(
"innocent rabbit"
)
==
false
Pour rendre la recherche insensible à la casse, transformons la chaîne de caractères en minuscule, puis recherchons :
function
checkSpam
(
str
)
{
let
lowerStr =
str.
toLowerCase
(
)
;
return
lowerStr.
includes
(
'viagra'
)
||
lowerStr.
includes
(
'xxx'
)
;
}
alert
(
checkSpam
(
'buy ViAgRA now'
)
)
;
alert
(
checkSpam
(
'free xxxxx'
)
)
;
alert
(
checkSpam
(
"innocent rabbit"
)
)
;