8000 repeatString exercise · fivan18/javascript-exercises@a5e6fbd · GitHub
[go: up one dir, main page]

Skip to content

Commit a5e6fbd

Browse files
author
Ivan
committed
repeatString exercise
1 parent e00a3bd commit a5e6fbd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

repeatString/repeatString.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
const repeatString = function() {
2-
1+
const repeatString = function(str, times) {
2+
if(times < 0){
3+
return 'ERROR';
4+
} else {
5+
let returnedStr = '';
6+
for(let i = 1; i <= times; i++){
7+
returnedStr += str;
8+
}
9+
return returnedStr;
10+
}
311
}
412

513
module.exports = repeatString

repeatString/repeatString.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ describe('repeatString', function() {
44
it('repeats the string', function() {
55
expect(repeatString('hey', 3)).toEqual('heyheyhey');
66
});
7-
xit('repeats the string many times', function() {
7+
it('repeats the string many times', function() {
88
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
99
});
10-
xit('repeats the string 1 times', function() {
10+
it('repeats the string 1 times', function() {
1111
expect(repeatString('hey', 1)).toEqual('hey');
1212
});
13-
xit('repeats the string 0 times', function() {
13+
it('repeats the string 0 times', function() {
1414
expect(repeatString('hey', 0)).toEqual('');
1515
});
16-
xit('returns ERROR with negative numbers', function() {
16+
it('returns ERROR with negative numbers', function() {
1717
expect(repeatString('hey', -1)).toEqual('ERROR');
1818
});
1919
});

0 commit comments

Comments
 (0)
0