es-toolkit/benchmarks/maxBy.bench.ts
HyunWoo Lee (Nunu Lee) 260bae963f
feat(maxBy): Add maxBy function that select element that have max value by given condition in array (#64)
* feat(maxBy): Add maxBy function

* feat(maxBy): Add benchamark test

* feat(maxBy): Add unit test of maxBy

* docs(maxBy): Add reference of maxBy function

* feat(maxBy): use for-each loop instead of index-increasing fashion

* fix(maxBy): Change code by code review

* fix(maxBy): Changed by code review, all tests are fine

* fix(maxBy): remove explicit undefined return

* fix(maxBy): Fix reference due to signature modification

* Update src/math/maxBy.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
2024-06-17 18:39:42 +09:00

24 lines
598 B
TypeScript
Executable File

import { bench, describe } from 'vitest';
import { maxBy as maxByToolkit } from 'es-toolkit';
import { maxBy as maxByLodash } from 'lodash';
describe('maxBy', () => {
bench('es-toolkit', () => {
const people = [
{ name: 'Mark', age: 25 },
{ name: 'Nunu', age: 30 },
{ name: 'Overmars', age: 20 },
];
maxByToolkit(people, person => person.age);
});
bench('lodash', () => {
const people = [
{ name: 'Mark', age: 25 },
{ name: 'Nunu', age: 30 },
{ name: 'Overmars', age: 20 },
];
maxByLodash(people, person => person.age);
});
});