小编Tiy*_*yor的帖子

检查字符串是否包含任何没有正则表达式的字符串数组

我正在检查字符串输入是否包含任何字符串数组。它通过了大部分测试,但没有通过以下测试。

谁能分解我的代码,为什么它不能正常工作?

     function checkInput(input, words) {
      var arr = input.toLowerCase().split(" ");
      var i, j;
      var matches = 0;
      for(i = 0; i < arr.length; i++) {
        for(j = 0; j < words.length; j++) {
          if(arr[i] == words[j]) {
            matches++;
          }
        }
      }
      if(matches > 0) {
        return true;
      } else {
        return false;
      }
    };

checkInput("Visiting new places is fun.", ["aces"]); // returns false // code is passing from this test
checkInput('"Definitely," he said in a matter-of-fact tone.', 
    ["matter", "definitely"])); …
Run Code Online (Sandbox Code Playgroud)

javascript arrays string

4
推荐指数
2
解决办法
8003
查看次数

标签 统计

arrays ×1

javascript ×1

string ×1