The minBy
function in lodash is used to get the minimum element of an array based on a provided comparer function. Here's an example of how to use minBy
in your javascript code:
146 chars7 lines
In this example, we pass an array of numbers to the minBy
function along with a comparer function that simply returns the number itself. The minBy
function then returns the minimum element of the array based on the returned values of the comparer function, which in this case is 2
.
It's worth noting that you can also use a property name string instead of the comparer function. Here's an example:
256 chars12 lines
In this example, we pass an array of students to the minBy
function along with the property name age
. The minBy
function then returns the student object with the minimum age
value, which in this case is { name: "Bob", age: 19 }
.
gistlibby LogSnag