DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
gustavoalias profile image
gustavoalias

Another approach


const lineChecker = (line, isFirstLine) => {
  if(line!=='')
    {
      return isFirstLine ? `<h1>${line}</h1>` : `<p>${line}</p>`
    }
  else {
    return "<br />";
  }
};

Enter fullscreen mode Exit fullscreen mode