Created
June 2, 2010 14:40
-
-
Save robinduckett/422445 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
String.prototype.closest2 = function(find, pos) { | |
var cur = 0; | |
while (cur <= this.length) { | |
if (pos + cur <= this.length) var is = this.substr(pos + cur, find.length); | |
if (pos - cur > 0) var it = this.substr(pos - cur, find.length); | |
if (is == find) return pos + cur; | |
if (it == find) return pos - cur; | |
cur++; | |
} | |
return -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment