mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
refactor - create types array to have named attributes
This commit is contained in:
parent
82c5a173b5
commit
fbb2d71f58
1 changed files with 7 additions and 5 deletions
|
|
@ -103,12 +103,14 @@ function getTypedArray(maxValue) {
|
|||
`Array maxValue must be an integer between 0 and 4294967295, got ${maxValue}`
|
||||
);
|
||||
|
||||
if (maxValue <= 255) return Uint8Array;
|
||||
if (maxValue <= 65535) return Uint16Array;
|
||||
if (maxValue <= 4294967295) return Uint32Array;
|
||||
if (maxValue <= UINT8_MAX) return Uint8Array;
|
||||
if (maxValue <= UINT16_MAX) return Uint16Array;
|
||||
if (maxValue <= UINT32_MAX) return Uint32Array;
|
||||
return Uint32Array;
|
||||
}
|
||||
|
||||
function createTypedArray({maxValue, length}) {
|
||||
return new (getTypedArray(maxValue))(length);
|
||||
function createTypedArray({maxValue, length, from}) {
|
||||
const typedArray = getTypedArray(maxValue);
|
||||
if (!from) return new typedArray(length);
|
||||
return typedArray.from(from);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue