DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
jameslongstaff profile image
jameslongstaff

Personally I'd do..



const lineChecker = (line, isFirstLine) => {
  let document = "<br />";

  if (line.length) {
    const tag = isFirstLine ? 'h1' : 'p';
    document = `<${tag}>${line}</${tag}>`;
  }

  return document;
};
Enter fullscreen mode Exit fullscreen mode