In theory you could avoid some of the memory overhead of the array returned by match() by instead using replace to generate a new string that contains only the newlines:
s.replace(/[^\n]/g, "").length
Unfortunately, there seems to be a bug in replace() that prevents this from working perfectly.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
In theory you could avoid some of the memory overhead of the array returned by
match()
by instead usingreplace
to generate a new string that contains only the newlines:Unfortunately, there seems to be a bug in replace() that prevents this from working perfectly.