mapkeep

1.0.1 • Public • Published

Build Status

mapkeep

Returns an array of the non-null results of fn(item, index). This means false return values will be included.
 
/**
 * Returns an array of the non-null/undefined results of fn(item, index).
 * This means false return values will be included.
 *
 * @param {Array} coll 
 * @param {Function} fn 
 * @param {Object} [ctx] 
 *
 * @return {Array} 
 */
function mapkeep(coll, fn, ctx) { }

Install

npm i -S mapkeep

Usage

var assert = require('assert');
var mapkeep = require('mapkeep');
 
function property(key) {
  return function(o) {
    return o[key];
  };
}
 
var arr = [
  { a: 1 },
  { a: 3 },
  { b: 4 } 
];
 
// will call `obj[key]` for each val where the key is `a`
var allAVals = mapkeep(arr, property('a'));
assert.deepEqual(allAVals, [1, 3]);

Package Sidebar

Install

npm i mapkeep

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • landau