I'm from Aguascalientes, Mexico! now based on New York. Most of my experience is related to code websites and applications, using JavaScript stack-based.
This is good, anyhow is an antipattern, it should be something like:
constconvertArrayToObject=(array,key)=>array.reduce((acc,curr)=>{acc[curr[key]]=curr;returnacc;},{});// Even conciseconstconvertArrayToObject=(array,key)=>array.reduce((acc,curr)=>(acc[curr[key]]=curr,acc),{});// Basically everything inside parentheses will be evaluated, only the last value used will be only returned.
In this way, you avoid the spread op which is a way expensive than a single assignment
Thanks for taking the time to help me and others out here! I am going to read up on the Comma operator in JavaScript developer.mozilla.org/en-US/docs/W... do you have any other resources you recomend here?
I was a bit surprised by your claim regarding the spread operator being anti-pattern so I asked around and it seems that there are different opinions regarding that. Would you care to throw in some info to shed more light on the topic?
Hey, man, I like code golfing too, but just because something can be written more concisely, it doesn't mean we should. Your second solution is kinda difficult to read because it's so cluttered and it also obligates people to know what the comma operator is and how it works. I just don't see how this is better than your first solution once the bundler will already minify the code for us, we don't need to write and read minified code, just be aware everyone, if you're gonna copy this, copy the first one, the people reading your code in the future will be happier :D
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is good, anyhow is an antipattern, it should be something like:
In this way, you avoid the spread op which is a way expensive than a single assignment
Thanks for taking the time to help me and others out here! I am going to read up on the Comma operator in JavaScript developer.mozilla.org/en-US/docs/W... do you have any other resources you recomend here?
There is no comma operator here
yes, there is, it's right above the line of the "Basically everything..."
I was a bit surprised by your claim regarding the spread operator being anti-pattern so I asked around and it seems that there are different opinions regarding that. Would you care to throw in some info to shed more light on the topic?
there is no item var around it should be curr did you even write that code alone?
Hey, man, I like code golfing too, but just because something can be written more concisely, it doesn't mean we should. Your second solution is kinda difficult to read because it's so cluttered and it also obligates people to know what the comma operator is and how it works. I just don't see how this is better than your first solution once the bundler will already minify the code for us, we don't need to write and read minified code, just be aware everyone, if you're gonna copy this, copy the first one, the people reading your code in the future will be happier :D