Skip to content

Commit 4548cb5

Browse files
committed
Update repeat function to handle positive, zero, negative, non-integer counts and repeat strings, numbers, booleans, null, undefined, arrays, and objects
1 parent aaa3da4 commit 4548cb5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sprint-3/2-practice-tdd/repeat.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
function repeat(valueToRepeat, numOfTimes) {
22
let repeatedValue = "";
3-
if (numOfTimes > 0) {
3+
if (numOfTimes > 0 && Number.isInteger(numOfTimes)) {
44
for (let i = 0; i < numOfTimes; i++) {
55
repeatedValue += valueToRepeat;
66
}
77
} else if (numOfTimes === 0) {
88
repeatedValue = "";
9-
}
10-
else {
9+
} else if(numOfTimes < 0) {
1110
repeatedValue = "Negative number invalid";
11+
} else if(!Number.isInteger(numOfTimes)) {
12+
repeatedValue = "Invalid count: count should be an integer"
1213
}
1314
return repeatedValue;
1415
}

0 commit comments

Comments
 (0)