Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
For me I go with faster + readable one, in this case I chose 1 it is readable but I don't see any performance difference between both of them
Out of scope, which language is this? using a single quote for strings, I guess it is Javascript? -
@gitpush yes JavaScript, the second was the original code by other dev, I hated it and the linter hated it, figured there must be a better way.
@Byscripts nice, didn't know how that would deal with null/undefined like that. Feels like I'm learning new things about JS all the time -
xsacha4317y@Byscripts definitely that is better. That is why I said 'out of those two' before because neither looked simple enough but I didn't want to test it.
-
@spongessuck probably not, but it doesn't feel like such a silly question now you have gone against the grain, so thanks!
-
@DucksCanCode umm what's that? Still beginner and don't have much PHP experiences.
-
@bcye like option one, where you have multiple method calls on the same line for the same object. I don't know if that's the proper name, that's just what I've always called it.
-
yusijs12507y@bcye this is in javascript - basically what is done in the original post is:
1) create an array with first name & surname
2) .filter() takes the array created in step1, and applies a function on it, returning a new array with the filtered values
3) .join() takes the array returned from step2, and joins the array with a space
Chained methods is basically:
- Start with an element (array in this case)
- Apply multiple functions to the element to return new values
For each chain (.filter, .map, .join etc), the value is returned and passed to the next chain, manipulating your data -
Also if pipes are approved in the new JS spec, function composition will look so much prettier
Related Rants
devRanters: 1 or 2?
Any alternative?
undefined
procrastinating