DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
derekenos profile image
Derek Enos

Here's my one-liner that includes a hilarious immediately-invoked arrow function:

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