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;
};
I refactored it and was thinking that it could be an excellent beginner-level refactoring kata.
How would you refactor it?