return s;
}
+ function reverse (s) {
+ return s.split("").reverse().join("");
+ }
+
function diffLerp(a, b, p) {
/** Interpolate between two strings based on edit distance
compute the edits. It is not recommended for strings
longer than a few hundred characters.
*/
+ a = reverse(a);
+ b = reverse(b);
var edits = diff(a, b);
var partial = edits.slice(0, Math.round(p * edits.length));
- return patch(partial, a);
+ return reverse(patch(partial, a));
}
var NUMBERS = /(-?\d+(?:\.\d+)?)/g;
}});
it("edits strings", function () { with (this) {
- assertEqual("Do you like green eggsSam-I-am.", lerp(A, B, 0.3));
- assertEqual("Do you like green Sam-I-am.", lerp(A, B, 0.5));
- assertEqual("do not like them, Sam-I-am.", lerp(A, B, 0.9));
+ assertEqual("I do not like treen eggs and ham?", lerp(A, B, 0.3));
+ assertEqual("I do not like them, Sggs and ham?", lerp(A, B, 0.5));
+ assertEqual("I do not like them, Sam-Iham?", lerp(A, B, 0.9));
}});
}});