or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash-reject

The lodash method reject exported as a module for filtering collections.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.reject@4.6.x

To install, run

npx @tessl/cli install tessl/npm-lodash-reject@4.6.0

index.mddocs/

Lodash Reject

The lodash.reject module provides the reject method from the lodash utility library as a standalone package. This method creates an array of elements that a predicate function returns falsy for, effectively filtering out elements that match the provided criteria.

Package Information

  • Package Name: lodash.reject
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.reject

Core Imports

const reject = require('lodash.reject');

ES6 module:

import reject from 'lodash.reject';

Basic Usage

const reject = require('lodash.reject');

const users = [
  { 'user': 'barney', 'age': 36, 'active': false },
  { 'user': 'fred',   'age': 40, 'active': true }
];

// Reject based on function predicate
const activeUsers = reject(users, function(o) { return !o.active; });
// => [{ 'user': 'fred', 'age': 40, 'active': true }]

// Reject using object predicate (matches properties)
const nonMatching = reject(users, { 'age': 40, 'active': true });
// => [{ 'user': 'barney', 'age': 36, 'active': false }]

// Reject using property-value pair predicate
const notInactive = reject(users, ['active', false]);
// => [{ 'user': 'fred', 'age': 40, 'active': true }]

// Reject using property name predicate
const inactive = reject(users, 'active');
// => [{ 'user': 'barney', 'age': 36, 'active': false }]

Capabilities

Reject Function

Creates an array of elements predicate returns falsy for. The opposite of _.filter; this method returns the elements of collection that predicate does NOT return truthy for.

/**
 * Creates an array of elements predicate returns falsy for.
 * @param {Array|Object} collection - The collection to iterate over.
 * @param {Function|Object|string} [predicate=_.identity] - The function invoked per iteration.
 * @returns {Array} Returns the new filtered array.
 */
function reject(collection, predicate);

Parameters:

  • collection (Array|Object): The collection to iterate over - can be an array or object
  • predicate (Function|Object|string, optional): The function invoked per iteration. Defaults to _.identity

Returns:

  • Array: Returns the new filtered array containing elements that do NOT match the predicate

Predicate Types:

  1. Function: function(value, index, collection) => boolean

    • Receives the current value, index/key, and collection
    • Return true to reject (exclude) the element
  2. Object: { property: value, ... }

    • Matches objects with the same property values (partial deep comparison)
    • Uses _.matches iteratee shorthand
  3. Array: [property, value]

    • Matches objects where object[property] === value
    • Uses _.matchesProperty iteratee shorthand
  4. String: 'property'

    • Matches objects where object[property] is truthy
    • Uses _.property iteratee shorthand

Usage Examples:

const reject = require('lodash.reject');

// Function predicate - reject active users
const users = [
  { name: 'Alice', active: true },
  { name: 'Bob', active: false },
  { name: 'Charlie', active: true }
];

const inactiveUsers = reject(users, user => user.active);
// => [{ name: 'Bob', active: false }]

// Object predicate - reject exact matches
const products = [
  { category: 'electronics', price: 100 },
  { category: 'books', price: 20 },
  { category: 'electronics', price: 200 }
];

const nonElectronics = reject(products, { category: 'electronics' });
// => [{ category: 'books', price: 20 }]

// Array predicate - reject by property-value pair
const items = [
  { type: 'urgent', priority: 1 },
  { type: 'normal', priority: 2 },
  { type: 'low', priority: 3 }
];

const nonUrgent = reject(items, ['type', 'urgent']);
// => [{ type: 'normal', priority: 2 }, { type: 'low', priority: 3 }]

// String predicate - reject by truthy property
const tasks = [
  { title: 'Task 1', completed: true },
  { title: 'Task 2', completed: false },
  { title: 'Task 3', completed: true }
];

const incompleteTasks = reject(tasks, 'completed');
// => [{ title: 'Task 2', completed: false }]

// With arrays of primitives
const numbers = [1, 2, 3, 4, 5, 6];
const evenNumbers = reject(numbers, n => n % 2 === 0);
// => [1, 3, 5]

// With objects (iterates over object values)
const scores = { alice: 85, bob: 92, charlie: 78 };
const belowNinety = reject(scores, score => score >= 90);
// => [85, 78]

Implementation Notes

  • Works with both arrays and objects (objects are iterated by their values)
  • Uses internal arrayFilter for arrays and baseFilter for objects
  • Predicate is normalized using getIteratee(predicate, 3) to handle different predicate types
  • Returns a new array; does not modify the original collection
  • For objects, the returned array contains the property values that don't match the predicate
  • Supports the same iteratee shorthands as other lodash methods (_.matches, _.matchesProperty, _.property)