Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function score(string,pattern) {
  2.     var points = 0, position = -1;
  3.     string = string.toLowerCase();
  4.     pattern = pattern.toLowerCase();
  5.     while (position != 0) { //When there is no pattern found, it will go back to -1 but because of position++ it will be 0
  6.         position = string.indexOf(pattern, position); //changes the position
  7.         if (position != -1) { //Add point if the pattern is found
  8.             points++
  9.         }
  10.         position++;
  11.     }
  12.     return points;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement