@bemoje/arr-last-where

1.0.2 • Public • Published

@bemoje/arr-last-where

Return the last element of an array where the callback returns true.

Version

NPM version

Travis CI

dependencies

Dependencies

dependencies

Stats

NPM downloads Forks

Donate

Buy Me A Beer donate button PayPal donate button

Installation

npm install @bemoje/arr-last-where
npm install --save @bemoje/arr-last-where
npm install --save-dev @bemoje/arr-last-where

Usage

import arrLastWhere from '@bemoje/arr-last-where'

const arr = [1, 2, 6, 3, 4, 5]

arrLastWhere(arr, (element) => {
	return element >= 5
})
//=> 5

arrLastWhere(arr, (element) => {
	return element >= 7
})
//=> null

Tests

Uses Jest to test module functionality. Run tests to get coverage details.

npm run test

API

arrLastWhere

Return the last element of an array where the callback returns true.

Parameters
  • arr Array The array to iterate

  • callback callback callback(element, index, array): boolean

Returns

any The last element to satisfy the condition in the callback

callback

Type: Function

Parameters
  • element any The current element

  • index number The current element's index in the array

  • array Array The array

Package Sidebar

Install

npm i @bemoje/arr-last-where

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

9.11 kB

Total Files

5

Last publish

Collaborators

  • bemoje