function repeatify(string, repetitions) {
if (repetitions < 0 || repetitions === Infinity) {
throw new RangeError('Invalid repetitions number');
}
let result = '';
for (let i = 0; i < repetitions; i++) {
result += string;
}
return result;
}
function repeatifyWithArrayAndJoin(string, repetitions) {
if (repetitions < 0 || repetitions === Infinity) {
throw new RangeError('Invalid repetitions number');
}
const result = [];
for (let i = 0; i < repetitions; i++) {
result.push(string);
}
return result.join('');
}
function repeatifyWithNewArray(string, repetitions) {
if (repetitions < 0 || repetitions === Infinity) {
throw new RangeError('Invalid repetitions number');
}
return new Array(repetitions).join(string);
}
function _checkRepeations(repetitions) {
if (repetitions < 0 || repetitions === Infinity) {
throw new RangeError('Invalid repetitions number');
}
}
function repeatifyWithNewArrayAndExternalThrow(string, repetitions) {
_checkRepeations(repetitions);
return new Array(repetitions).join(string);
}
function repeatifyWithNewArrayAndExternalThrowWithProps(string, repetitions) {
this.checkRepeations(repetitions);
return new this.Array(repetitions).join(string);
}
var ctx = {
checkRepeations: _checkRepeations,
Array: Array
}
repeatifyWithNewArrayAndExternalThrowWithProps = repeatifyWithNewArrayAndExternalThrowWithProps.bind(ctx);
var TEST_STRING = 'home, sweet home';
var COUNT = 1e6;