DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Other than shortening it a bit, I'd change the second parameter:

const lineChecker = (ilne, followup) =>   line
  ? followup
      ? `<p>${line}</p>`
      : `<h1>${line}</h1>`
   : `<br>`
Enter fullscreen mode Exit fullscreen mode

Why switch the boolean around? Because now you can do

let liens = ["Title", "", "paragraph"].map(lineChecker)
Enter fullscreen mode Exit fullscreen mode