diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index 50f34c7..e044e6e 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -2,13 +2,12 @@ const repeatString = function(string, number) { let result = ''; + if (number < 0) { + return 'ERROR'; + } + for (let i = 0; i < number; i++) { - if (number < 0) { - return 'ERROR'; - } - result += string; - } return result; diff --git a/repeatString/repeatString.spec.js b/repeatString/repeatString.spec.js index 20bff3f..d7fa59b 100644 --- a/repeatString/repeatString.spec.js +++ b/repeatString/repeatString.spec.js @@ -13,7 +13,7 @@ describe('repeatString', function() { it('repeats the string 0 times', function() { expect(repeatString('hey', 0)).toEqual(''); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(repeatString('hey', -1)).toEqual('ERROR'); }); xit('repeats the string a random amount of times', function() {