const projects = [
{ id: 'a', stars: 10 },
{ id: 'b', stars: 30 },
{ id: 'c', stars: 20 },
];
const mostStars = Arr.maxBy(projects, (project) => project.stars);
const smallestStars = Arr.maxBy(
projects,
(project) => project.stars,
(a, b) => b - a,
);
assert.deepStrictEqual(mostStars, Optional.some({ id: 'b', stars: 30 }));
assert.deepStrictEqual(smallestStars, Optional.some({ id: 'a', stars: 10 }));
Finds the element with the maximum mapped value.
const projects = [
{ id: 'a', stars: 10 },
{ id: 'b', stars: 30 },
{ id: 'c', stars: 20 },
];
const mostStars = Arr.maxBy(projects, (project) => project.stars);
const smallestStars = Arr.maxBy(
projects,
(project) => project.stars,
(a, b) => b - a,
);
assert.deepStrictEqual(mostStars, Optional.some({ id: 'b', stars: 30 }));
assert.deepStrictEqual(smallestStars, Optional.some({ id: 'a', stars: 10 }));
Finds the element with the maximum mapped value.