Skip to content

Commit ce61555

Browse files
corrected errors in tests and commited the changes
1 parent 9b54862 commit ce61555

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
function repeatStr() {
2-
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
3-
// The goal is to re-implement that function, not to use it.
4-
return String.repeat(count);
1+
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
2+
// The goal is to re-implement that function, not to use it.
3+
function repeatStr(str, count) {
4+
if (typeof str !== "string" || typeof count !== "number" || count < 0) {
5+
throw new Error(
6+
"Invalid input: str must be a string and count must be a non-negative integer"
7+
);
8+
}
9+
10+
let result = "";
11+
12+
for (let i = 0; i < count; i++) {
13+
result += str;
14+
}
15+
16+
return result;
517
}
618

719
module.exports = repeatStr;

0 commit comments

Comments
 (0)