Comparing version 0.20.3 to 0.21.0
@@ -206,2 +206,33 @@ 'use strict'; | ||
/** | ||
* Find method returns the value of first element at which a provided function is true, | ||
* or undefined if no elements in the array satisfy the function. | ||
* | ||
* @param {Array} array | ||
* @param {Function} predicate to be run against each element of the array | ||
* @param {*} thisArg of this | ||
* @returns {*} value of element that satisfied function. | ||
* @example | ||
* const result = arrays.find([5, 12, 8, 130, 44], (x) => x > 10); | ||
* console.log(result); | ||
* > 12 | ||
* @example | ||
* const result = arrays.find([5, 12, 8, 130, 44], function(x) { return x > this }, 4); | ||
* console.log(result); | ||
* > 5 | ||
*/ | ||
function find (array, predicate, thisArg = undefined) { | ||
if (array.length === 0) return undefined; | ||
if (this == null) { throw TypeError('"this" is null or not defined'); } | ||
if (typeof predicate !== 'function') { throw TypeError('predicate must be a function'); } | ||
if (predicate.call(thisArg, array[0])) return array[0]; | ||
if (array.length === 1) return undefined; | ||
return array.reduce((res, cur, i) => { | ||
if (i === 1) return predicate.call(thisArg, cur) ? cur : undefined; | ||
if (!res && predicate.call(thisArg, cur)) return cur; | ||
return res; | ||
}); | ||
} | ||
/** | ||
* IndexOf method returns the first index at which a given element can be found in the array | ||
@@ -327,2 +358,3 @@ * beyond the starting index, or -1 if it is not present. | ||
filter: filter, | ||
find: find, | ||
indexOf: indexOf, | ||
@@ -329,0 +361,0 @@ map: map, |
@@ -202,2 +202,33 @@ /** | ||
/** | ||
* Find method returns the value of first element at which a provided function is true, | ||
* or undefined if no elements in the array satisfy the function. | ||
* | ||
* @param {Array} array | ||
* @param {Function} predicate to be run against each element of the array | ||
* @param {*} thisArg of this | ||
* @returns {*} value of element that satisfied function. | ||
* @example | ||
* const result = arrays.find([5, 12, 8, 130, 44], (x) => x > 10); | ||
* console.log(result); | ||
* > 12 | ||
* @example | ||
* const result = arrays.find([5, 12, 8, 130, 44], function(x) { return x > this }, 4); | ||
* console.log(result); | ||
* > 5 | ||
*/ | ||
function find (array, predicate, thisArg = undefined) { | ||
if (array.length === 0) return undefined; | ||
if (this == null) { throw TypeError('"this" is null or not defined'); } | ||
if (typeof predicate !== 'function') { throw TypeError('predicate must be a function'); } | ||
if (predicate.call(thisArg, array[0])) return array[0]; | ||
if (array.length === 1) return undefined; | ||
return array.reduce((res, cur, i) => { | ||
if (i === 1) return predicate.call(thisArg, cur) ? cur : undefined; | ||
if (!res && predicate.call(thisArg, cur)) return cur; | ||
return res; | ||
}); | ||
} | ||
/** | ||
* IndexOf method returns the first index at which a given element can be found in the array | ||
@@ -323,2 +354,3 @@ * beyond the starting index, or -1 if it is not present. | ||
filter: filter, | ||
find: find, | ||
indexOf: indexOf, | ||
@@ -325,0 +357,0 @@ map: map, |
{ | ||
"name": "absurdum", | ||
"version": "0.20.3", | ||
"version": "0.21.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
], | ||
"repository": "https://github.com/vanillajs2/absurdum", | ||
"repository": "https://github.com/vanillaes/absurdum", | ||
"author": "Evan Plaice <evanplaice@gmail.com>", | ||
@@ -15,0 +15,0 @@ "license": "MIT", |
@@ -1,6 +0,6 @@ | ||
[![GitHub release](https://img.shields.io/github/release/vanillajs2/absurdum.svg)](https://github.com/vanillajs2/absurdum/releases) | ||
[![GitHub release](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
[![npm](https://img.shields.io/npm/v/absurdum.svg)](https://www.npmjs.com/package/absurdum) | ||
[![David](https://img.shields.io/david/dev/vanillajs2/absurdum.svg)](https://david-dm.org/vanillajs2/absurdum?type=dev) | ||
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vanillajs2/absurdum/master/LICENSE) | ||
[![Actions Status](https://github.com/vanillajs2/absurdum/workflows/Release/badge.svg)](https://github.com/vanillajs2/absurdum/actions) | ||
[![David](https://img.shields.io/david/dev/vanillaes/absurdum.svg)](https://david-dm.org/vanillaes/absurdum?type=dev) | ||
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vanillaes/absurdum/master/LICENSE) | ||
[![Actions Status](https://github.com/vanillaes/absurdum/workflows/Release/badge.svg)](https://github.com/vanillaes/absurdum/actions) | ||
@@ -57,2 +57,3 @@ # Absurdum | ||
- [filter][arrays.filter] | ||
- [find][arrays.find] | ||
- [indexOf][arrays.indexOf] | ||
@@ -72,2 +73,3 @@ - [map][arrays.map] | ||
[arrays.filter]: ./docs/arrays/filter.md | ||
[arrays.find]: ./docs/arrays/find.md | ||
[arrays.indexOf]: ./docs/arrays/indexOf.md | ||
@@ -74,0 +76,0 @@ [arrays.map]: ./docs/arrays/map.md |
@@ -9,2 +9,3 @@ export { chunk } from "./chunk.js"; | ||
export { filter } from "./filter.js"; | ||
export { find } from './find.js'; | ||
export { indexOf } from "./indexOf.js"; | ||
@@ -11,0 +12,0 @@ export { map } from "./map.js"; |
@@ -9,2 +9,3 @@ export { chunk } from './chunk.js'; | ||
export { filter } from './filter.js'; | ||
export { find } from './find.js'; | ||
export { indexOf } from './indexOf.js'; | ||
@@ -11,0 +12,0 @@ export { map } from './map.js'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
71166
67
1866
102