Advertisement
Guest User

Untitled

a guest
May 5th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. /*jshint multistr:true */
  2.  
  3. var text = "blah blah Benjamin blah blah blah Benjamin";
  4. var myName = "Benjamin";
  5. var hits = [];
  6.  
  7. for (var i=0; i < text.length; i++) {
  8. if (text[i] === myName[0]) {
  9. for(j = i; j < i + myName.length; j++) {
  10. if(text[j]===myName[j-i]) {
  11. hits.push(text[j]);
  12. }
  13. }
  14. }
  15. }
  16.  
  17. if (hits.length > 2 ) {
  18. console.log(hits);
  19. } else {
  20. console.log("Name Not here");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement