Program of text search has a bug


#1

Your program of text search has a bug as the program checks only first letter of the name with the text and then push elements until your name length. lets take an example in the given below code my first letter of name is v output of this will be wrong

var text="hhhh vipul vhhh hhh hhh hh\
vipul hhh hhh hhh hh hh vipul";
var myName="vipul";
var hits=[];
for(i=0; i<text.length;i=i+1)
{
    if(text[i]===myName[0])
    {
        for(j=i;j<=i+myName.length;j++)
        {
            hits.push(text[j]);
        }
    }
}
if(hits.length===0)
{
    console.log("Your name wasn't found!");
}
else
{
    console.log(hits);
}


#2

Not a bug, but the intention of the author. This is a learning experience and not a production script. Unless there is something else you are pointing out that I fail to see?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.