Given a string, return true if the number of appearances of "is" anywhere in the string is equal to the number of appearances of "not" anywhere in the string (case sensitive). Complete function isNot (including the function heading) to accomplish this. The following assertions must pass.
console.assert( isNot("isisnotnot") )
console.assert( isNot("isnot") )
console.assert( isNot("_not_is_not_is_") )
console.assert( isNot( "abc" ) ) // zero is's, zero nots
console.assert( isNot("_is_is_not_") === false )
function isNot(str){
var numIs=0;
var numNot=0;
var ind=str.indexOf("is",0);
while(ind!=-1){
numIs+=1;
ind = str.indexOf("is",ind+2);
}
ind=str.indexOf("not",0);
while(ind!=-1){
numNot+=1;
ind = str.indexOf("not",ind+3);
}
return (numNot==numIs);
}
Get Answers For Free
Most questions answered within 1 hours.