commit
efde1e3846
|
@ -1,9 +1,13 @@
|
||||||
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) {
|
||||||
|
return 'ERROR';
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < times; i++) {
|
||||||
arr.push(word);
|
arr.push(word);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return arr.join('');
|
return arr.join('');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue