background.js
//with modification by kigiri (https://gist.github.com/kigiri) on Nov 26, 2016

with modification by kigiri  on Nov 26, 2016
with modification by kigiri on Nov 26 2016
function levenshtein(a, b) {
  if(a.length === 0) return b.length;
  if(b.length === 0) return a.length;
  if(a.length > b.length) {
    let tmp = a;
    a = b;
    b = tmp;
  }
  const aLen = a.length;
  let row = new Array(aLen + 1);
  for(let i = 0; i <= aLen; i++) {
    row[i] = i;
  }
  for(let i = 1; i <= b.length; i++) {
    let prev = i;
    for(let j = 1; j <= aLen; j++) {
      let val;
      if(b[i-1] === a[j-1]) {  
        val = row[j-1];
      } else {
        val = Math.min(
          row[j - 1] + 1, 
          Math.min(prev + 1, row[j] + 1 )
        );
      }
      row[j - 1] = prev;
      prev = val;
    }
    row[aLen] = prev;
  }
  return row[aLen];
}
function levenshtein ( a , b ) { if ( a . length === 0 ) return b . length ; if ( b . length === 0 ) return a . length ; if ( a . length > b . length ) { let tmp = a ; a = b ; b = tmp ; } const aLen = a . length ; let row = new Array ( aLen + 1 ) ; for ( let i = 0 ; i <= aLen ; i ++ ) { row [ i ] = i ; } for ( let i = 1 ; i <= b . length ; i ++ ) { let prev = i ; for ( let j = 1 ; j <= aLen ; j ++ ) { let val ; if ( b [ i - 1 ] === a [ j - 1 ] ) { val = row [ j - 1 ] ; } else { val = Math . min ( row [ j - 1 ] + 1 , Math . min ( prev + 1 , row [ j ] + 1 ) ) ; } row [ j - 1 ] = prev ; prev = val ; } row [ aLen ] = prev ; } return row [ aLen ] ; }
with modification by kigiri (https://gist.github.com/kigiri) on Nov 26, 2016
with modification by kigiri ( https : // gist . github . com / kigiri ) on Nov 26 2016
//swap to save some memory O(min(a,b)) instead of O(a)
 //match
 /*subst*/ /*insert*/ /*dele*/