Reverse edit strings so they change LTR, like fastLerp.
[string-lerp.git] / string-lerp.js
index 5e8201c..2096a07 100644 (file)
         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;