system_assignation/node_modules/repeating/index.js

25 lines
396 B
JavaScript
Raw Normal View History

2022-03-24 09:22:39 -04:00
'use strict';
var isFinite = require('is-finite');
module.exports = function (str, n) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string as the first argument');
}
if (n < 0 || !isFinite(n)) {
throw new TypeError('Expected a finite positive number');
}
var ret = '';
do {
if (n & 1) {
ret += str;
}
str += str;
} while (n = n >> 1);
return ret;
};