Skip to content

Commit 45d06e1

Browse files
authored
Merge pull request #522 from MaoShizhong/repeat-string-test
02_repeatString: Replace regex test with built-in repeat method
2 parents ace1d6e + c5d806b commit 45d06e1

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

02_repeatString/repeatString.spec.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ describe('repeatString', () => {
2424
expect(repeatString('goodbye', -1)).toEqual('ERROR');
2525
});
2626
test.skip('repeats the string a random amount of times', function () {
27-
/*The number is generated by using Math.random to get a value from between
28-
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
29-
equals a number between 0 to 999 (this number will change everytime you run
30-
the test).*/
27+
/* The number is generated by using Math.random to get a value from between
28+
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
29+
equals a number between 0 to 999 (this number will change everytime you run
30+
the test).
3131
32-
// DO NOT use Math.floor(Math.random() * 1000) in your code,
33-
// this test generates a random number, then passes it into your code with a function parameter.
34-
// 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
35-
const number = Math.floor(Math.random() * 1000)
36-
/*The .match(/((hey))/g).length is a regex that will count the number of heys
37-
in the result, which if your function works correctly will equal the number that
38-
was randomly generated. */
39-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
32+
DO NOT use Math.floor(Math.random() * 1000) in your code,
33+
this test generates a random number, then passes it into your code with a function parameter.
34+
If this doesn't make sense, you should go read about functions here:
35+
https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 */
36+
const number = Math.floor(Math.random() * 1000);
37+
expect(repeatString('hey', number)).toBe('hey'.repeat(number));
4038
});
4139
test.skip('works with blank strings', () => {
4240
expect(repeatString('', 10)).toEqual('');

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@ describe('repeatString', () => {
2424
expect(repeatString('goodbye', -1)).toEqual('ERROR');
2525
});
2626
test('repeats the string a random amount of times', function () {
27-
/*The number is generated by using Math.random to get a value from between
28-
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
29-
equals a number between 0 to 999 (this number will change everytime you run
30-
the test).*/
27+
/* The number is generated by using Math.random to get a value from between
28+
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
29+
equals a number between 0 to 999 (this number will change everytime you run
30+
the test).
3131
32-
// DO NOT use Math.floor(Math.random() * 1000) in your code,
33-
// this test generates a random number, then passes it into your code with a function parameter.
34-
// 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
32+
DO NOT use Math.floor(Math.random() * 1000) in your code,
33+
this test generates a random number, then passes it into your code with a function parameter.
34+
If this doesn't make sense, you should go read about functions here:
35+
https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3 */
3536
const number = Math.floor(Math.random() * 1000);
36-
/*The .match(/((hey))/g).length is a regex that will count the number of heys
37-
in the result, which if your function works correctly will equal the number that
38-
was randomly generated. */
39-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
40-
number
41-
);
37+
expect(repeatString('hey', number)).toBe('hey'.repeat(number));
4238
});
4339
test('works with blank strings', () => {
4440
expect(repeatString('', 10)).toEqual('');

0 commit comments

Comments
 (0)