Socket
Book a DemoInstallSign in
Socket

map-arr

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-arr

A tiny, faster alternative to native Array.prototype.map

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

map-arr Build Status

A tiny (124b), faster alternative to native Array.prototype.map!

JavaScript's native Array.prototype.map is (unfortunately) *much slower than standard for-loops.

This module has no dependencies and serves as a drop-in replacement for Node.js and the browser!

It is ES3-compatible, which means it will run on any browser and be the fastest version you can use.

Lastly, it is CommonJS & ES-Module friendly :tada:

Install

$ npm install --save map-arr

Usage

// import mapArr from 'map-arr';
const mapArr = require('map-arr');

mapArr(['foo', 'bar', 'baz'], el => {
	return el + el;
});
//=> ['foofoo', 'barbar', 'bazbaz']

mapArr(['foo', 'bar', 'baz'], (el, idx) => {
	return el + idx;
});
//=> ['foo0', 'bar1', 'baz2']

API

This module is a drop-in replacement for Array.prototype.map, which means it has the same API and behavior!

Benchmarks

native
  --> 141,953 ops/sec ±0.15% (95 runs sampled)
map-arr
  --> 4,202,912 ops/sec ±0.72% (94 runs sampled)
arr-map
  --> 3,820,479 ops/sec ±0.37% (96 runs sampled)
array-map
  --> 135,490 ops/sec ±1.15% (92 runs sampled)

License

MIT © Luke Edwards

Keywords

arr

FAQs

Package last updated on 05 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts