Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Commit

Permalink
move levenshtein() from lib.js
Browse files Browse the repository at this point in the history
  • Loading branch information
andyholmes committed Aug 5, 2017
1 parent 5b61156 commit eaaf295
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ function getPath() {
imports.searchPath.push(getPath());
const Convenience = imports.lib;

// https://gist.github.com/andrei-m/982927#gistcomment-2059365
String.prototype.levenshtein = function(b){
var a = this, tmp;
if (a.length === 0) { return b.length; }
if (b.length === 0) { return a.length; }
if (a.length > b.length) { tmp = a; a = b; b = tmp; }

var i, j, res, alen = a.length, blen = b.length, row = Array(alen);
for (i = 0; i <= alen; i++) { row[i] = i; }

for (i = 1; i <= blen; i++) {
res = i;
for (j = 1; j <= alen; j++) {
tmp = row[j - 1];
row[j - 1] = res;
res = b[i - 1] === a[j - 1] ? tmp : Math.min(tmp + 1, Math.min(res + 1, row[j] + 1));
}
}
return res;
};

// infer backend and init Device()
if (ARGV[0].split("/")[2] === "mconnect") {
var DEVICE = new imports.mconnect.Device(ARGV[0]);
Expand Down Expand Up @@ -554,6 +575,7 @@ const Application = new Lang.Class({

vfunc_startup: function() {
this.parent();

this._window = new ApplicationWindow({ application: this });
},

Expand Down

0 comments on commit eaaf295

Please sign in to comment.