Skip to content

Files

Latest commit

 

History

History

145-minby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

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