Implement a function maxBy(array, iteratee) that finds the maximum element in an array based on the specified criteria.
The function should:
array and an iteratee function.iteratee to each element to generate a criterion for comparison.undefined if the array is empty.Examples
maxBy([1, 2, 3, 4], x => x); // 4 maxBy([{ n: 1 }, { n: 2 }], o => o.n); // { n: 2 } maxBy(['apple', 'banana', 'kiwi'], s => s.length); // "banana" maxBy([], x => x); // undefined
JavaScript Function
No test results yet
Click "Run" to execute tests