Created
June 21, 2013 21:47
-
-
Save eduardolundgren/5834588 to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script> | |
(function() { | |
var p1 = "bananai", | |
p2 = "na", | |
index = -1, | |
i, | |
p2len = p2.length; | |
for (i = 0; i < p1.length; i++) { | |
if (index < 0) { | |
if (p1[i] === p2[0]) { | |
index = i; | |
} | |
} | |
else if ( ( ((i - index) < p2len) && (p1[i] !== p2[i - index]) ) ) { | |
index = -1; | |
i--; | |
} | |
} | |
console.log('index:', index); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment