Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(at): Improve performance and compatibility with lodash #798

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

filipsobol
Copy link
Contributor

@filipsobol filipsobol commented Nov 6, 2024

It turns out that the native .at() is kinda slow and the behavior when non-integer numbers are used in the indices array is inconsistent with lodash implementation of .at().

import { at as atLodash } from 'lodash-es';
import { at } from 'es-toolkit';

console.log(atLodash([1, 2, 3], [1.5, -1.5, NaN, Infinity, -Infinity])); // [undefined, undefined, undefined, undefined, undefined]
console.log(at([1, 2, 3], [1.5, -1.5, NaN, Infinity, -Infinity])); // [2, 3, 1, undefined, undefined]

This PR improves performance (especially in big arrays) and improve consistency with lodash implementation.


Performance before:
Before


Performance after:
After

Copy link

vercel bot commented Nov 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 10:15am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant