https://github.com/coderaiser/mapcar
applies function to elements of lists with same index
https://github.com/coderaiser/mapcar
Last synced: 9 months ago
JSON representation
applies function to elements of lists with same index
- Host: GitHub
- URL: https://github.com/coderaiser/mapcar
- Owner: coderaiser
- License: mit
- Created: 2015-10-07T09:27:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T08:25:41.000Z (almost 8 years ago)
- Last Synced: 2025-06-18T06:08:03.588Z (10 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
# Mapcar [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
Mapcar applies function `fn` to elements of lists with same index.
Each application result is put into resulting `list`.
Length of resulting list is the length of the shortest list argument.
Came from [lisp](http://jtra.cz/stuff/lisp/sclr/mapcar.html).
## Install
```
npm i mapcar --save
bower i mapcar --save
```
## How to use?
```js
mapcar(sum, [1,2,3,4], [1,2]);
// returns
[2,4]
function sum(array) {
return array.reduce(function(value, item) {
return value + item;
}, 0);
}
```
## License
MIT
[NPMIMGURL]: https://img.shields.io/npm/v/mapcar.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/mapcar/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/mapcar.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/mapcar "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/mapcar "Build Status"
[DependencyStatusURL]: https://david-dm.org/coderaiser/mapcar "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"