https://github.com/coderaiser/mapsome
find maped element of an array that will satisfy condition of some
https://github.com/coderaiser/mapsome
Last synced: about 1 month ago
JSON representation
find maped element of an array that will satisfy condition of some
- Host: GitHub
- URL: https://github.com/coderaiser/mapsome
- Owner: coderaiser
- License: mit
- Created: 2016-07-04T16:49:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T08:25:45.000Z (almost 8 years ago)
- Last Synced: 2026-01-23T20:51:12.960Z (2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mapsome [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage][CoverageIMGURL]][CoverageURL]
Find maped element of an array that will satisfy condition of some.
[Map][mapURL] + [Some][someURL] + `early return of an element`
## Install
```
npm i mapsome --save
```
## How come?
Lets look at regular `map-filter` example:
```js
const map = (a) => ++a;
const condition = (a) => a > 2;
[1, 2, 3, 4]
.map(map) /* loop full array */
.filter(condition) /* loop full array again */
.pop(); /* get value */
// returns
3
```
With `mapsome` this would look this way:
```js
const map = (a) => ++a;
const condition = (a) => a > 2;
mapsome(map, condition, [1, 2, 3, 4]);
// returns
3
```
`mapsome` works much faster because no need map full array, first satisfied condition will break the loop.
## API
### mapsome(map [, condition ], array)
- mapping function
- condition of stopping the loop
- array
`mapsome` could be used with `map` function only:
```js
const map = (a) => ++a;
mapsome(map, [0, 0, 3, 0]);
// returns
3
// same as
mapsome(map, a => a, [0, 0, 3, 0]);
// returns
3
```
## Environments
### Node.js
In old `node.js` environments that supports `es5` only, `mapsome` could be used with:
```js
var mapsome = require('mapsome/legacy');
```
### Web Browser
`mapsome` could be installed via `bower` with:
```sh
bower install mapsome --save
```
When loaded in browser `mapsome` uses global variable with same name (when `browserify` or `webpack` did not used).
## License
MIT
[NPMIMGURL]: https://img.shields.io/npm/v/mapsome.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/mapsome/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/mapsome.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/mapsome "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/mapsome "Build Status"
[DependencyStatusURL]: https://david-dm.org/coderaiser/mapsome "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/coderaiser/mapsome?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/mapsome/badge.svg?branch=master&service=github
[someURL]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
[mapURL]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map