projects
/
string-lerp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reverse edit strings so they change LTR, like fastLerp.
[string-lerp.git]
/
string-lerp.js
diff --git
a/string-lerp.js
b/string-lerp.js
index
5e8201c
..
2096a07
100644
(file)
--- a/
string-lerp.js
+++ b/
string-lerp.js
@@
-79,6
+79,10
@@
return s;
}
return s;
}
+ function reverse (s) {
+ return s.split("").reverse().join("");
+ }
+
function diffLerp(a, b, p) {
/** Interpolate between two strings based on edit distance
function diffLerp(a, b, p) {
/** Interpolate between two strings based on edit distance
@@
-88,9
+92,11
@@
compute the edits. It is not recommended for strings
longer than a few hundred characters.
*/
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));
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;
}
var NUMBERS = /(-?\d+(?:\.\d+)?)/g;