Well, if all you want is to count lines with assumption that \n means new line, i would suggest using something simpler (i assume it would be faster, but thats for someone else to test out).
consttext="hello \n world \n !!!"constcount=(text.match(/\n/g)||[]).length+1;count// 3
Hi Paweł, thanks for the reply. I am not sure if using match instead of split is simpler or just another way to count lines. And there's another point, using split, enables us to count words, characters, and spaces. How do you achieve this goal with match? I think this adds more complexity instead of developing what we already have.
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.
Well, if all you want is to count lines with assumption that
\n
means new line, i would suggest using something simpler (i assume it would be faster, but thats for someone else to test out).Hi Paweł, thanks for the reply. I am not sure if using
match
instead ofsplit
is simpler or just another way to count lines. And there's another point, usingsplit
, enables us to count words, characters, and spaces. How do you achieve this goal withmatch
? I think this adds more complexity instead of developing what we already have.