epeli/underscore.string — Issue #84: chop improvement
Author: ajax333221
Created: 2012-02-16 04:20:45+00:00
State: open

Change:

chop: sArgs(function(str, step){
step = parseNumber(step) || str.length;
var arr = [];
for (var i = 0; i < str.length;) {
arr.push(str.slice(i,i + step));
i = i + step;
}
return arr;
}),

To:

chop: sArgs(function(str, step){
step = parseNumber(step) || str.length;
for (var i = 0, len = str.length, arr = []; i < len; i += step) {
arr.push(str.slice(i,i + step));
}
return arr;
}),

Explanation:
-storing the length: why would we check the length EVERY loop, if the length is not going to change?
-moving the arr = []: but with this change we don't write 'var' twice
-improving the ' i = i + step' to 'i += step': it would be interesting
-moving the 'i += step' to the top: with this, the minified version would save two chars (the '{}' of the loop)

kthxbye