From 4910737064e364ac5f2525c43dff9e01365be3c2 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 12 Jul 2021 14:08:42 -0600 Subject: [PATCH] Improve arraySeed utility This is a tiny microimprovement, but worthwhile the more we use it. --- src/utils/arrays.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/arrays.ts b/src/utils/arrays.ts index 6524debfb7..3f9dcbc34b 100644 --- a/src/utils/arrays.ts +++ b/src/utils/arrays.ts @@ -112,11 +112,9 @@ export function arrayRescale(input: number[], newMin: number, newMax: number): n * @returns {T[]} The array. */ export function arraySeed(val: T, length: number): T[] { - const a: T[] = []; - for (let i = 0; i < length; i++) { - a.push(val); - } - return a; + // Size the array up front for performance, and use `fill` to let the browser + // optimize the operation better than we can with a `for` loop, if it wants. + return new Array(length).fill(val); } /**