8000 Replace regex test with String.prototype.repeat test · rokuruby/javascript-exercises@c5d806b · GitHub
[go: up one dir, main page]

Skip to content

Commit c5d806b

Browse files
committed
Replace regex test with String.prototype.repeat test
Easier for learners to understand test and does not require extra explanation of regex
1 parent 15d4dd0 commit c5d806b

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

02_repeatString/repeatString.spec.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ describe('repeatString', () => {
2626
this test generates a random number, then passes it into your code with a function parameter.
2727
If this doesn't make sense, you should go read about functions here:
2828
https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 */
29-
const number = Math.floor(Math.random() * 1000)
30-
/*The .match(/((hey))/g).length is a regex that will count the number of heys
31-
in the result, which if your function works correctly will equal the number that
32-
was randomly generated. */
33-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
29+
const number = Math.floor(Math.random() * 1000);
30+
expect(repeatString('hey', number)).toBe('hey'.repeat(number));
3431
});
3532
test.skip('works with blank strings', () => {
3633
expect(repeatString('', 10)).toEqual('');

02_repeatString/solution/repeatString-solution.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ describe('repeatString', () => {
2727
If this doesn't make sense, you should go read about functions here:
2828
https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 */
2929
const number = Math.floor(Math.random() * 1000);
30-
/*The .match(/((hey))/g).length is a regex that will count the number of heys
31-
in the result, which if your function works correctly will equal the number that
32-
was randomly generated. */
33-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
34-
number
35-
);
30+
expect(repeatString('hey', number)).toBe('hey'.repeat(number));
3631
});
3732
test('works with blank strings', () => {
3833
expect(repeatString('', 10)).toEqual('');

0 commit comments

Comments
 (0)
0