检查 spam
重要程度: 5
写一个函数 checkSpam(str)
,如果 str
包含 viagra
或 XXX
就返回 true
,否则返回 false
。
函数必须不区分大小写:
checkSpam
(
'buy ViAgRA now'
)
==
true
checkSpam
(
'free xxxxx'
)
==
true
checkSpam
(
"innocent rabbit"
)
==
false
为了使搜索不区分大小写,我们将字符串改为小写,然后搜索:
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"
)
)
;