Skip to content

Commit b91f950

Browse files
refactor repeat function to improve input validation and error handling
1 parent 7198839 commit b91f950

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function repeat(str,count) {
2-
3-
if(count<0){
4-
return "Error: negative numbers are not valid";
1+
function repeat(str, count) {
2+
if (count < 0 || count === undefined || typeof count !== "number") {
3+
return "Error : count must be a positive integer";
54
}
6-
return (str.repeat(count));
5+
if (count === 0) {
6+
return "";
7+
}
8+
return str.repeat(count);
79
}
810

911
module.exports = repeat;
10-

0 commit comments

Comments
 (0)