Skip to content

Commit 4f4b1b2

Browse files
authored
Merge pull request #20 from solome/patch-1
Update `arrayRepeat.ts` to fix 'Maximum call stack size exceeded' with an empty array parameter.
2 parents 5405aee + c6df3d9 commit 4f4b1b2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/utils/arrayRepeat.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* // returns ["cyan", "red", "cyan", "red"]
66
*/
77
function arrayRepeat(array: string[], length: number = 0): Array<string> {
8+
if (array.length === 0) {
9+
throw new Error("Input array cannot be empty!");
10+
}
11+
812
const colorArray: Array<string> = [];
913

1014
function repeatToLength(array: string[], length: number = 0): Array<string> {

0 commit comments

Comments
 (0)