renovations
This commit is contained in:
parent
4b8b168fd2
commit
c7d4c7e3ff
172 changed files with 869 additions and 244 deletions
17
1-js/4-data-structures/3-string/2-check-spam/solution.md
Normal file
17
1-js/4-data-structures/3-string/2-check-spam/solution.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
Метод `indexOf` ищет совпадение с учетом регистра. То есть, в строке `'xXx'` он не найдет `'XXX'`.
|
||||
|
||||
Для проверки приведем к нижнему регистру и строку `str` а затем уже будем искать.
|
||||
|
||||
```js
|
||||
//+ run
|
||||
function checkSpam(str) {
|
||||
var lowerStr = str.toLowerCase();
|
||||
|
||||
return !!(~lowerStr.indexOf('viagra') || ~lowerStr.indexOf('xxx'));
|
||||
}
|
||||
|
||||
alert( checkSpam('buy ViAgRA now') );
|
||||
alert( checkSpam('free xxxxx') );
|
||||
alert( checkSpam("innocent rabbit") );
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue