lukeed

map-arr

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 🎉

#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

See also

clsx(3), @polka/cluster(3), @pwa/cli(3), uvu(3), taskr(3), sockette(3), klona(3), kleur(3), dequal(3), sirv-cli(3)