Simple Issues and can’t find fix
I have been set a task for this code to return true,true,false, [0,1] and [0,2]
Nothing to advanced it should be simple but i just can’t see it
function match(string,pattern){
var d=0;
for(var e = 0; e<pattern.length; e++)
{
var r =pattern.toLowerCase().charAt(e);
if(r>='a' && r<='z'){
if(string.toLowerCase().indexOf(r)==-1){
d=0;
}else{
d=1;
}
}
}
if (d===0)
return(false);
else
return(true);
}
//answer.true.true.false
alert(match("abcdef","@C2D!"));
alert(match("abcdef","CAfe"));
alert(match("abcdef", "CG"));
var contents = [ "Loughborough University offers degree programmes and world class research.", "An alternative University",
"Yet another University"];
var match=match;
function matchContents(contents,pattern) { var result=[];
for(var i=0;i<contents.length;i++){if (match(contents[i],pattern)) result[result.length]=i;
}
return result;
}
alert(matchContents(contents,"other"));//Should equal[0,1]
alert(matchContents(contents,"LU"));//Should equal [0,2]