@jswork/next-min-by
v1.0.3
Published
This method is like _.min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.
Downloads
63
Readme
next-min-by
This method is like _.min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.
installation
yarn add @jswork/next-min-by
usage
import '@jswork/next-min-by';
// given an array of objects
const arr = [
{ name: 'apple', value: 10 },
{ name: 'banana', value: 20 },
{ name: 'orange', value: 15 },
{ name: 'pear', value: 25 }
];
// find the min value by `value` property
const result = nx.minBy(arr, 'value');
// result: { name: 'apple', value: 10 }
// find the min value by function
const result2 = nx.minBy(arr, (item) =>item.value);
// result: { name: 'apple', value: 10 }
license
Code released under the MIT license.