Created
December 8, 2015 15:21
-
-
Save anitahall102790/16c2a3dd963044df6cd2 to your computer and use it in GitHub Desktop.
Search Text for your Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text = "Anita, Anita, Anita, Anita, Anita, Anita,Anita,Anita,Anita,"; | |
var myName = "Anita"; | |
var hits = []; | |
for (i=0; i<text.length; i++) { | |
if (text[i] === 'A') { | |
for( j = i; j < (myName.length + i) ; j++){ | |
hits.push(text[j]); | |
} | |
} | |
} | |
if(hits.length === 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