DEV Community

loading...

Discussion on: Avoid use IF on our JS scripts

Collapse
victoor profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Víctor Falcón

True, and some example on this article are horrible, in my opinion.

That second ternary almost explode my brain.

Collapse
carlosbbt profile image
Carlos Moran

And the lack of spacing, my eslint config would choke on the examples.

Thread Thread
damxipo profile image
Damian Cipolat Author

They were not developed using eslint, you can execute them directly from node in a new project

Collapse
lucamuscat profile image
Luca Muscat

Slight correction, it's no longer a ternary if it contains more than 3 values on the right hand side (it becomes an n-ary operator ;) )

Thread Thread
damxipo profile image
Damian Cipolat Author

NICE thanks for the data

Collapse
damxipo profile image
Damian Cipolat Author

well bad luck, thanks for your opinion. I consider more horrible a code like this:

export const removeProps = (source: Object, props: Array, keepReceivedProps: boolean = true) => {
return Object.keys(source).forEach(key => {
if (keepReceivedProps) {
if (!props.find(item => item == key)) delete source[key];
} else {
if (props.find(item => item == key)) delete source[key];
}
});
};

This code is from a project make maybe from JAVA developers that come to JS or for JS Jr developer. the if nesting I think is very bad. So for this reason I'm looking for alternatives to avoid write this type of code and publish material to try the developers in find new alternatives