Emperor01 / JSlearn

all my practical trainings
0 stars 0 forks source link

let's work #5

Open Emperor01 opened 6 years ago

Emperor01 commented 6 years ago

function CheckSpam (word) { word = word.toLowerCase(); var firstresult = word.indexOf("viagra"); var secondresult = word.indexOf("xxx"); return (firstresult == -1 || secondresult == -1) ? true : false; }

alert(CheckSpam('Viagra')); alert(CheckSpam('noViagra')); alert(CheckSpam('danceviagra'));

//check spam words like viagra and xxx //but they have this solution of this task

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") );

//their variant is better?