10000 Add function to satisfy test requirements · rhawkenson/javascript-exercises@35e6b3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 35e6b3d

Browse files
committed
Add function to satisfy test requirements
1 parent bd60a13 commit 35e6b3d

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

repeatString/repeatString.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
const repeatString = function() {
2-
1+
const repeatString = function(text, num){
2+
let string ='';
3+
if (num < 0 ){
4+
string += 'ERROR';
5+
} else {
6+
for (let i=0; i<num; i++){
7+
string += text;
8+
}
9+
}return string;
310
}
411

512
module.exports = repeatString

repeatString/repeatString.spec.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
const repeatString = require('./repeatString')
22

33
describe('repeatString', function() {
4+
//Test 1
45
it('repeats the string', function() {
56
expect(repeatString('hey', 3)).toEqual('heyheyhey');
67
});
7-
xit('repeats the string many times', function() {
8+
9+
//Test 2
10+
it('repeats the string many times', function() {
811
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
912
});
10-
xit('repeats the string 1 times', function() {
13+
14+
//Test 3
15+
it('repeats the string 1 times', function() {
1116
expect(repeatString('hey', 1)).toEqual('hey');
1217
});
13-
xit('repeats the string 0 times', function() {
18+
19+
//Test 4
20+
it('repeats the string 0 times', function() {
1421
expect(repeatString('hey', 0)).toEqual('');
1522
});
16-
xit('returns ERROR with negative numbers', function() {
23+
24+
//Test 5
25+
it('returns ERROR with negative numbers', function() {
1726
expect(repeatString('hey', -1)).toEqual('ERROR');
1827
});
19-
xit('repeats the string a random amount of times', function () {
28+
29+
//Test 6
30+
it('repeats the string a random amount of times', function () {
2031
/*The number is generated by using Math.random to get a value from between
2132
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
2233
equals a number between 0 to 999 (this number will change everytime you run
@@ -27,7 +38,9 @@ describe('repeatString', function() {
2738
was randomaly generated. */
2839
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
2940
});
30-
xit('works with blank strings', function() {
41+
42+
//Test 7
43+
it('works with blank strings', function() {
3144
expect(repeatString('', 10)).toEqual('');
3245
});
3346
});

0 commit comments

Comments
 (0)
0