mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Optimized repeat and its tests
This commit is contained in:
@@ -12,8 +12,17 @@
|
||||
return literal === string.substr(string.length - len - (back || 0), len);
|
||||
};
|
||||
|
||||
exports.repeat = function(string, n) {
|
||||
return (Array(n + 1)).join(string);
|
||||
exports.repeat = function(str, n) {
|
||||
var res;
|
||||
res = '';
|
||||
while (n > 0) {
|
||||
if (n & 1) {
|
||||
res += str;
|
||||
}
|
||||
n >>>= 1;
|
||||
str += str;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
exports.compact = function(array) {
|
||||
|
||||
Reference in New Issue
Block a user