From 206397e4bd8fc6dbeeade1f5bf02676acb5970e9 Mon Sep 17 00:00:00 2001 From: Matthew McEachen Date: Mon, 4 Nov 2024 10:53:22 -0800 Subject: [PATCH] Refactor times function to use Array.from for improved readability --- src/Times.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Times.ts b/src/Times.ts index a8632f04..c0dca303 100644 --- a/src/Times.ts +++ b/src/Times.ts @@ -1,5 +1,9 @@ +/** + * Generates an array by running a function n times + * @param n The number of times to run the function + * @param fn The function to generate each element + * @returns An array containing the results + */ export function times(n: number, f: (idx: number) => T): T[] { - return Array(n) - .fill(undefined) - .map((_, i) => f(i)) + return Array.from({ length: n }, (_, i) => f(i)) }