projects
/
string-lerp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
203ddaf
)
No reason to split into sourceParts, use the regex to extract matches directly.
author
Joe Wreschnig
<joe.wreschnig@gmail.com>
Mon, 19 May 2014 08:44:51 +0000
(10:44 +0200)
committer
Joe Wreschnig
<joe.wreschnig@gmail.com>
Mon, 19 May 2014 08:44:51 +0000
(10:44 +0200)
string-lerp.js
patch
|
blob
|
history
diff --git
a/string-lerp.js
b/string-lerp.js
index
8e3ef64
..
bb799a4
100644
(file)
--- a/
string-lerp.js
+++ b/
string-lerp.js
@@
-195,11
+195,11
@@
numerals gives undefined results.
*/
numerals gives undefined results.
*/
- var sourceParts = source.split(NUMBERS);
var targetParts = target.split(NUMBERS);
var targetParts = target.split(NUMBERS);
- var destParts = targetParts;
- for (var i = 1; i < sourceParts.length; i += 2) {
- var sourcePart = sourceParts[i];
+ var match;
+ var i = 1;
+ while ((match = NUMBERS.exec(source))) {
+ var sourcePart = match[0];
var targetPart = targetParts[i];
var part = nlerp(+sourcePart, +targetPart, amount);
var sourcePoint = sourcePart.indexOf(".");
var targetPart = targetParts[i];
var part = nlerp(+sourcePart, +targetPart, amount);
var sourcePoint = sourcePart.indexOf(".");
@@
-209,6
+209,7
@@
targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0,
amount));
targetParts[i] = part.toFixed(point);
targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0,
amount));
targetParts[i] = part.toFixed(point);
+ i += 2;
}
return targetParts.join("");
}
}
return targetParts.join("");
}