mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 10:15:43 +03:00
Improve arraySeed utility
This is a tiny microimprovement, but worthwhile the more we use it.
This commit is contained in:
parent
1b39dbdb53
commit
4910737064
1 changed files with 3 additions and 5 deletions
|
@ -112,11 +112,9 @@ export function arrayRescale(input: number[], newMin: number, newMax: number): n
|
|||
* @returns {T[]} The array.
|
||||
*/
|
||||
export function arraySeed<T>(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<T>(length).fill(val);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue