Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function score(string,pattern) {
- var points = 0, position = -1;
- string = string.toLowerCase();
- pattern = pattern.toLowerCase();
- while (position != 0) { //When there is no pattern found, it will go back to -1 but because of position++ it will be 0
- position = string.indexOf(pattern, position); //changes the position
- if (position != -1) { //Add point if the pattern is found
- points++
- }
- position++;
- }
- return points;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement