Counting the number of occurrences in a string using a higher-order function
I was recently working on some code that required me to count the number of occurrences of an @ in a string. Initially, I created the following:
const matches = (email.match("@")||[]).length;
However, the ||[] which defaults to an empty array if no ...
chris-seaton.co.uk1 min read