Skip to content

Instantly share code, notes, and snippets.

@GeekaholicLin
Created September 2, 2016 03:32
Show Gist options
  • Select an option

  • Save GeekaholicLin/a340ed8625286cb2297449ca0c1eb388 to your computer and use it in GitHub Desktop.

Select an option

Save GeekaholicLin/a340ed8625286cb2297449ca0c1eb388 to your computer and use it in GitHub Desktop.
find if the string contains the characters of substring or not[判断字符串是否包含字符,与顺序无关]
function mutation(arr) {
  //build a regexp
  var regStr = "";
  arr[1].split("").forEach(function(val){
      regStr +="(?=.*?"+val.toLowerCase()+")";
    //just like this "/(?=.*?a)(?=.*?b)(?=.*?c)/"
  });
  var regObj = new RegExp(regStr,"i");
  return regObj.test(arr[0]);
}

mutation(["hello", "hey"]);

refer to this blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment