DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
rkallan profile image
RRKallan • Edited

understandable and readable is very hard in your solution.
Refactor is not to get code smaller.

I prefer === checks instead ==
I prefer !?.length instead l.length == 0

According to w3 guidelines, a space should be included before the trailing / and > of empty elements, for example, <br />. These guidelines are for XHTML documents to render on existing HTML user agents.

edited

Collapse
 
calinbaenen profile image
Calin Baenen • Edited

understandable and readable is very hard in your solution.
Refactor is not to get code smaller.

Then I think the people who submitted those one-liners (Which are even harder to understand than my code!) misunderstood the point. :p

Thread Thread
 
rkallan profile image
RRKallan

the one line solutions with nested ternary expressions are also difficult to understand.

Thread Thread
 
rkallan profile image
RRKallan

Goals for refactoring code: readability, understandability, maintainability, performance, usage of latest code style / programming / functions / methods

Collapse
 
calinbaenen profile image
Calin Baenen

According to w3 guidelines, a space should be included before the trailing / and > of empty elements, for example,

I don't think your example works as intended.

Also, why is that? Does the space do something to make the HTML more understandable to some interpreters?

Thread Thread
 
rkallan profile image
RRKallan

edited my comment

According to w3 guidelines, a space should be included before the trailing / and > of empty elements, for example, <br />. These guidelines are for XHTML documents to render on existing HTML user agents.