packed-array

1.2.2 • Public • Published

packed-array

Social Media Photo by Elevate on Unsplash

Build Status Coverage Status

An utility to create fast, non-holey arrays.

import packedArray from 'packed-array';
const packedArray = require('packed-array');
 
// via unpkg, as global utility
// <script src="https://unpkg.com/packed-array">

API

This utility has the exact same Array.from API, except the first parameter can be an integer, as length, and the second one can be just a static value, to fill the Array of specified length with such value.

const array = packedArray(
  length, // either a number, or an object/array with a {length}
  fill,   // either a static value, or a function used via Array.from
  thisArg // optionally, if `fill` is a function, it will be passed as context
);

Goal

Simplify the creation of arrays extremely fast to be looped or consumed within their length boundaries.

Native Alternative

If you're after just arrays with a length and some initial value, the following would likely perform better, producing the same result:

// note the Array(length) is mandatory to obtain a packed kind
const array = Array.from(Array(length), () => value);

Readme

Keywords

Package Sidebar

Install

npm i packed-array

Weekly Downloads

87

Version

1.2.2

License

ISC

Unpacked Size

6.03 kB

Total Files

9

Last publish

Collaborators

  • webreflection