Skip to content

Commit

Permalink
fix: string.repeat after recent regression
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 18, 2017
1 parent 5b553c2 commit b02fab4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
18 changes: 10 additions & 8 deletions string/#/repeat/shim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-bitwise: "off" */

// Thanks: http://www.2ality.com/2014/01/efficient-string-repeat.html
// Thanks
// @rauchma http://www.2ality.com/2014/01/efficient-string-repeat.html
// @mathiasbynens https://github.com/mathiasbynens/String.prototype.repeat/blob/4a4b567def/repeat.js

"use strict";

Expand All @@ -12,11 +12,13 @@ module.exports = function (count) {
count = toInteger(count);
if (count < 0) throw new RangeError("Count must be >= 0");
if (!isFinite(count)) throw new RangeError("Count must be < ∞");
if (!count) return "";
if (count === 1) return str;

result = "";
if (count & 1) result += str;
while ((count >>>= 1)) str += str;
return result + str;
while (count) {
if (count % 2) result += str;
if (count > 1) str += str;
// eslint-disable-next-line no-bitwise
count >>= 1;
}
return result;
};
1 change: 1 addition & 0 deletions test/string/#/repeat/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = function (t, a) {
a(t.call("raz", 3), "razrazraz", "Many chars");
a(t.call("raz", 3), "razrazraz", "Many chars");
a(t.call("razfoobar", 5), "razfoobarrazfoobarrazfoobarrazfoobarrazfoobar", "Many chars");
a(t.call("a", 300).length, 300);
};

0 comments on commit b02fab4

Please sign in to comment.