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

False positive for prefer-lodash-chain with _.range? #257

Open
danvk opened this issue Jul 27, 2020 · 1 comment
Open

False positive for prefer-lodash-chain with _.range? #257

danvk opened this issue Jul 27, 2020 · 1 comment

Comments

@danvk
Copy link

danvk commented Jul 27, 2020

I have this function to produce nPoints of data on a curve:

const generateData = (nPoints: number) =>
  _.range(0, nPoints).map(i => {
    // Inverse tanh on (-0.9, +0.9); just something to get a distribution.
    const x = (1.9 * i) / nPoints - 0.95;
    const atanh = Math.log1p(x) - Math.log1p(-x);
    return {row: i, atanh};
  });

The prefer-lodash-chain rule flags this because of the _.range followed by the map. It's not clear what I'm supposed to replace this with, though. It would have to be something like _(_.range(0, nPoints)).map(...).value(), which doesn't seem like an improvement.

@alldayalone
Copy link

alldayalone commented Nov 17, 2021

@danvk You can you _.times instead. https://lodash.com/docs/4.17.15#times

_.range(0, nPoints).map(i => {

_.times(nPoints, i => {

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

No branches or pull requests

2 participants