GitHub 6248★

Check if a string consists of a repeated character sequence

JavaScript version

const consistsRepeatedSubstring = (str) => `${str}${str}`.indexOf(str, 1) !== str.length;

TypeScript version

const consistsRepeatedSubstring = (str: string): boolean => `${str}${str}`.indexOf(str, 1) !== str.length;

Examples

consistsRepeatedSubstring('aa'); // true
consistsRepeatedSubstring('aaa'); // true
consistsRepeatedSubstring('ababab'); // true
consistsRepeatedSubstring('abc'); // false
Follow me on and to get more useful contents.