GitHub 6521★

Repeat a string

JavaScript version

const repeat = (str, numberOfTimes) => str.repeat(numberOfTimes);

// Or
const repeat = (str, numberOfTimes) => Array(numberOfTimes + 1).join(str);

TypeScript version

const repeat = (str: string, numberOfTimes: number): string => str.repeat(numberOfTimes);

// Or
const repeat = (str: string, numberOfTimes: number): string => Array(numberOfTimes + 1).join(str);
Follow me on and to get more useful contents.