Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
Created February 4, 2015 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehoshua02/a44289a57437ad6ac53c to your computer and use it in GitHub Desktop.
Save jehoshua02/a44289a57437ad6ac53c to your computer and use it in GitHub Desktop.
Jim's answer

Jim,

You gotta make sure the limit for the second loop is the starting point plus the length of your name.

/*jshint multistr:true */

var text = "Hey, how are you \
doing? My name is Joshua Stoutenburg.";
var myName = 'Joshua Stoutenburg';
var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === myName[0]) {
        for (var j = i; j < i + myName.length; j++) {
            hits.push(text[j]);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment