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 chainable on minBy #37

Closed
corbinu opened this issue Mar 8, 2016 · 1 comment
Closed

False positive for chainable on minBy #37

corbinu opened this issue Mar 8, 2016 · 1 comment
Labels

Comments

@corbinu
Copy link

corbinu commented Mar 8, 2016

I am getting a false positive for chainable

I am starting with an array like this:

let test = [
    {
        "name": "a",
        "age": 18
    },
    {
        "name": "b",
        "age": 21
    },
    {
        "name": "a",
        "age": 55
    }
];

I want to convert this to the min age for each name
Correct end result is

[{"name": "a", "age": 18},{"name": "b", "age": 21}]

I am trying this:

testResult = _(test)
    .groupBy("name") // {"a": [{"name": "a", "age": 18}, {"name": "a", "age": 55}], "b": [{"name": "b", "age": 21}]}
    .map((sameName) => _.minBy(sameName, "age")) // [{"name": "a", "age": 18}, {"name": "b", "age": 21}]
    .value();

OR

let groupedNames = _.groupBy(test, "name");
testResult = _.map(groupedNames, (sameName) => _.minBy(sameName, "age"));

I am not sure why I get an error on both of these of "refer lodash chain (lodash/prefer-lodash-chain)"
This seems to be incorrect as minBy is not chainable

Perhaps there is a better way though?

@ganimomer
Copy link
Contributor

Hi,
This is generally what I would do for this problem (either is fine, though I prefer chaining, since it doesn't require creating intermediate variables).
This looks like it really is a false positive, we'll look into it.

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

No branches or pull requests

2 participants