Permalink
Browse files

Merge pull request #1 from a8m/master

Incorporate recent changes
  • Loading branch information...
bignall committed Aug 15, 2016
2 parents f46dff8 + a33ac45 commit e745c47774ded63a4c942e647986c0c597a2cf7b
Showing with 17 additions and 9 deletions.
  1. +17 −9 src/_common.js
View
@@ -60,15 +60,23 @@ function objectContains(partial, object) {
* @returns {*}
*/
function hasApproxPattern(word, pattern) {
if(pattern === '')
return word;
var index = word.indexOf(pattern.charAt(0));
if(index === -1)
return false;
return hasApproxPattern(word.substr(index+1), pattern.substr(1))
// cheaper version of indexOf; instead of creating each
// iteration new str.
function indexOf(word, p, c) {
var j = 0;
while ((p + j) <= word.length) {
if (word.charAt(p + j) == c) return j;
j++;
}
return -1;
}
var p = 0;
for (var i = 0; i <= pattern.length; i++) {
var index = indexOf(word, p, pattern.charAt(i));
if (index == -1) return false;
p += index + 1;
}
return true
}
/**

0 comments on commit e745c47

Please sign in to comment.