@n3okill/utils
Version:
Many javascript helpers
26 lines • 793 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.repeat = repeat;
/**
* Repeat a given string a number of times
* @param str String that will be repeated
* @param n Number of times to repeat the given string
* @return The given string repeated n times
*/
function repeat(str, n) {
let result = "";
if (n < 1) {
return "";
}
while (n > 0) {
//Examples of bitwise operators can be seen at
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
if (n & 1) {
result += str;
}
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
(n >>= 1), (str += str);
}
return result;
}
//# sourceMappingURL=repeat.js.map
;