Merge pull request #12 from BillalPatel/repeat-string

Tidy up
This commit is contained in:
Billal Patel 2019-11-04 22:07:47 +00:00 committed by GitHub
commit efde1e3846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -1,8 +1,12 @@
const repeatString = function(word, times) { const repeatString = function(word, times) {
let arr = word.split(' '); let arr = [];
for (let i = 1; i < times; i++) { if (times < 0) {
arr.push(word); return 'ERROR';
} else {
for (let i = 0; i < times; i++) {
arr.push(word);
}
} }
return arr.join(''); return arr.join('');

View File

@ -9,7 +9,7 @@ describe('repeatString', function() {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
}); });
it('repeats the string 1 times', function() { it('repeats the string 1 time', function() {
expect(repeatString('hey', 1)).toEqual('hey'); expect(repeatString('hey', 1)).toEqual('hey');
}); });