DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
panthablack profile image
panthablack

The most pressing concern here (imo) is the function name - I don't know what it is meant to do, and certainly doesn't just 'check' lines - it constructs lines of HTML based on the arguments passed in and returns a string.

To refactor I would first look at the function in context and rename it something appropriate based on its intended use - the next steps would likely be as much to do with preferred style as anything else after that point. (Personally I lean towards declarative so I liked the solutions I have seen in the comments where the code was DRYed up using clearly named, reusable functions, but this is just personal preference.)

Collapse
 
rkallan profile image
RRKallan

you touching a good point about the function name.
But the case is refactor a peace of code.
Would you rename the function, or would you write a new function with the correct understandable name also for the param?