Replace regex test with String.prototype.repeat test

Easier for learners to understand test and does not require extra explanation of regex
This commit is contained in:
MaoShizhong
2025-02-04 03:51:30 +00:00
parent 15d4dd07e7
commit c5d806b88c
2 changed files with 3 additions and 11 deletions
@@ -27,12 +27,7 @@ describe('repeatString', () => {
If this doesn't make sense, you should go read about functions here:
https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 */
const number = Math.floor(Math.random() * 1000);
/*The .match(/((hey))/g).length is a regex that will count the number of heys
in the result, which if your function works correctly will equal the number that
was randomly generated. */
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
number
);
expect(repeatString('hey', number)).toBe('hey'.repeat(number));
});
test('works with blank strings', () => {
expect(repeatString('', 10)).toEqual('');