2 Star 0 Fork 0

mirrors_WebReflection/packed-array

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
ISC

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);
ISC License Copyright (c) 2020, Andrea Giammarchi, @WebReflection Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

简介

An utility to create fast, non-holey, arrays 展开 收起
README
ISC
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_WebReflection/packed-array.git
git@gitee.com:mirrors_WebReflection/packed-array.git
mirrors_WebReflection
packed-array
packed-array
master

搜索帮助