FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Find Minimum by Iteratee

10 mins

Write a function minBy(array, iteratee) that looks through an array and returns the element for which the provided iteratee function produces the smallest value.

⚠️ If the iteratee returns null or undefined for every element, the function should return undefined.

Examples:

minBy([2, 3, 1, 4], (num) => num); // => 1 minBy([{ n: 1 }, { n: 2 }], (o) => o.n); // => { n: 1 } minBy([{ n: 1 }, { n: 2 }], (o) => o.m); // => undefined

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests