Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 1.77 KB

File metadata and controls

18 lines (13 loc) · 1.77 KB

minBy easy #javascript

by Pawan Kumar @jsartisan

Take the Challenge

Implement a function similar to _.minBy from the Lodash library. The function minBy takes an array of objects and an iteratee (a function that extracts the value to be compared from each object) and returns the object with the minimum value. If the array is empty, it should return undefined.

Example Usage:

const users = [
  { user: 'barney', age: 36 },
  { user: 'fred', age: 40 },
  { user: 'pebbles', age: 1 }
];

const youngest = minBy(users, o => o.age);
console.log(youngest); // { user: 'pebbles', age: 1 }

Back Share your Solutions Check out Solutions