DEV Community

Discussion on: Lodash and Underscore, is there still a case?

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

The first part of what you mentioned, I'm not convinced that this is not already covered by popular es6 array methods unless I am missing something?

Collapse
 
amyblankenship profile image
AmyBlankenship • Edited

Can you provide an example of syntax where you'd provide a string with the path to a deeply nested object property to use in ES6 map or where you'd be able to provide an object that describes a property and value to filter on? If such exists, I have never seen it described anywhere. AFAIK those methods always take a function.

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

I don't think one method does exist off the top of my head. Can you give me a data structure snippet to visualize.

I guess you might want to use entries and perhaps flat, not working on nested data but flat copies, that's got to be more efficient.. maybe. IDK but I agree that convince sounds like the winner here. Anyway I always check this sort of opinion, it's interesting. 😁

Thread Thread
 
amyblankenship profile image
AmyBlankenship • Edited

So, if your data structure is

[{firstName: 'John', lastName: 'Smith', offspring: [{name:'Katie', gender: 'F'}, {name: 'Mark', gender: 'M'}],
{firstName: 'Jill', lastName: 'Jones', offSpring: [{name: 'Doug', gender: 'M'}]}]

and you're looking for someone whose firstborn is a son (in case of pestilence), you can do _.find(users, ['offspring[0].gender', 'M'])

Or if you want the last name of the second user, you can do _.get(users, '[1].lastName')

Or if you want to find all users with offspring
_.filter(users, 'offspring.length')

I just don't see easily being able to do that with native ES6 functions out of the box.

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€ • Edited
const arr = [{
    firstName: 'John',
    lastName: 'Smith',
    offspring: [{
        name:'Katie', 
        gender: 'F'
    }, {
        name: 'Mark',
        gender: 'M'
    }],
    {
        firstName: 'Jill', 
        lastName: 'Jones', 
        offSpring: [{
            name: 'Doug', 
            gender: 'M'
        }]
    }
];

arr.find(person => person.offspring.find ... // Point taken this is a bit more wordy😁
Thread Thread
 
amyblankenship profile image
AmyBlankenship

So in other words, you can't do it out of the box with ES6 functions--you have to write additional functionality yourself (which your team is then responsible for testing and maintaining).