diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index 28befb1..0107520 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -1,8 +1,12 @@ const repeatString = function(word, times) { - let arr = word.split(' '); - - for (let i = 1; i < times; i++) { - arr.push(word); + let arr = []; + + if (times < 0) { + return 'ERROR'; + } else { + for (let i = 0; i < times; i++) { + arr.push(word); + } } return arr.join(''); diff --git a/repeatString/repeatString.spec.js b/repeatString/repeatString.spec.js index cf38828..bad3406 100644 --- a/repeatString/repeatString.spec.js +++ b/repeatString/repeatString.spec.js @@ -9,7 +9,7 @@ describe('repeatString', function() { 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'); });