Skip to content

Instantly share code, notes, and snippets.

@marlibs3-zz
Created November 9, 2015 07:13
Show Gist options
  • Save marlibs3-zz/e6877fd85b3397715c26 to your computer and use it in GitHub Desktop.
Save marlibs3-zz/e6877fd85b3397715c26 to your computer and use it in GitHub Desktop.
Find my Name
/*jshint multistr:true */
var text = "One day Marta went to the shops and ate an entire chicken.\
She was so full that the chicken wings came out of her back and Marta became a hybrid chicken human. As she went rabid and started pecking people Andrew started crying and shouting 'Marta! No!'. It was all very sad because they all died."
var myName = "Marta"
var hits = []
for (var i = 0; i < text.length; i++)
{
if (text[i] === 'M')
{
for (var j = i; j < i + myName.length; j++)
{
hits.push(text[j]);
}
}
}
if (hits === 0)
{
console.log("Your name wasn't found!")
}
else
{
console.log(hits)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment