Skip to content

Instantly share code, notes, and snippets.

@coder618
Created September 29, 2018 08:14
Show Gist options
  • Save coder618/3f0405afefb48520e240982def76cd28 to your computer and use it in GitHub Desktop.
Save coder618/3f0405afefb48520e240982def76cd28 to your computer and use it in GitHub Desktop.
Words matcher
function words_match ($bigStr,$smallStr ){
var match_words = '';
$bigStr = $bigStr.trim();
$smallStr = $smallStr.trim();
if( $smallStr.indexOf(',') > 0 ){
// If string contain multiple item
var sm_array = $smallStr.split(",");
match_words = _.filter( sm_array , function(item) {
return $bigStr.toLowerCase().match( item.toLowerCase() );
});
}else{
// If string contain one value
if($bigStr.indexOf($smallStr) >= 0){
match_words = $smallStr;
}
}
if( match_words.length > 0 ){
return true;
}else return false;
// console.log(match_words);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment