There is a small bug in your last solution
const isEmpty = (line) => line !== '' && line != null;
returns false when line = "" and true when line = "test"
possible solution
const isEmpty = (line) => !line && line !== 0; const isFirstLine = (index) => !index; const getElementTag = (index) => (isFirstLine(index) ? "h1" : "p"); const getText = (line, index) => { const elementTag = getElementTag(index); const text = `<${elementTag}>${line}</${elementTag}>`; return text; }; const br = () => "<br />"; const lineChecker = (line = "", index) => { if (isEmpty(line)) return br(); return getText(line, index); }; const checkLines = (lines = []) => lines.map(lineChecker);
the easiest way to check for all falsy values would be if(!!line === false)
if(!!line === false)
What do you think about?
If(!line)
Ohh my bad. Thanks for pointing it out! I did not run the code after the refactor (big mistake when refactoring)
haha can happen :)
It definitely does, I've been away from javascript for a while, mostly working with dart/flutter...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There is a small bug in your last solution
returns false when line = "" and true when line = "test"
possible solution
the easiest way to check for all falsy values would be
if(!!line === false)
What do you think about?
Ohh my bad. Thanks for pointing it out! I did not run the code after the refactor (big mistake when refactoring)
haha can happen :)
It definitely does, I've been away from javascript for a while, mostly working with dart/flutter...