I have the simple following code :
var S = require('string');
function matchBlacklist(inputString) {
var blacklist = ["facebook", "wikipedia", "search.ch", "local.ch"];
var found = false;
for (var i = 0; i < blacklist.length; i++) {
if (S(inputString).contains(blacklist[i]) > -1) {
found = true;
}
}
return (found);
}
matchBlacklist("www.facebook.com/this_is_a_test"); // returns true
matchBlacklist("www.example.com/this_is_a_test"); // returns true
But it always returns true; as it should return false for the second case
found = true;and then continuing with the for loop, why not justreturn true;to exit the loop?