mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 12:05:41 +03:00
7c824629ee
* feat(flatten): add faltten (#137) * fix: fix lint * fix: fix test code description * test(flatten): add test case * Update docs/ko/reference/array/flatten.md * Update docs/ko/reference/array/flatten.md * Update docs/ko/reference/array/flatten.md * Update docs/reference/array/flatten.md --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
28 lines
665 B
TypeScript
28 lines
665 B
TypeScript
import { bench, describe } from 'vitest';
|
|
import { flatten as flattenToolkit } from 'es-toolkit';
|
|
import { flattenDepth as flattenDepthLodash } from 'lodash';
|
|
|
|
const createNestedArray = (values: any[]) => {
|
|
if (values.length === 0) {
|
|
return [];
|
|
}
|
|
const [first, ...rest] = values;
|
|
return [first, createNestedArray(rest)];
|
|
};
|
|
|
|
describe('flatten', () => {
|
|
const arr = createNestedArray(Array.from({ length: 30 }, (_, index) => index));
|
|
|
|
bench('es-toolkit/flatten', () => {
|
|
flattenToolkit(arr, 30);
|
|
});
|
|
|
|
bench('lodash/flattenDepth', () => {
|
|
flattenDepthLodash(arr, 30);
|
|
});
|
|
|
|
bench('js built-in/flat', () => {
|
|
arr.flat(30);
|
|
});
|
|
});
|