How would you refactor this JS function?

Lars Grammel - Oct 18 '21 - - Dev Community

During the weekend, I found the following small JS function in a blog post:

const lineChecker = (line, isFirstLine) => {
  let document = ``;

  if (line !== "" && isFirstLine) {
    document += `<h1>${line}</h1>`;
  } else if (line !== "" && !isFirstLine) {
    document += `<p>${line}</p>`;
  } else if (line === "") {
    document += "<br />";
  }

  return document;

};
Enter fullscreen mode Exit fullscreen mode

I refactored it and was thinking that it could be an excellent beginner-level refactoring kata.

How would you refactor it?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .