I'm working through some JS problems over at edabit and am having some issues with this one. The task asks us to create a function that returns the number of hashes and pluses in a string and return the answer in an array. It returns [0,0] if given an empty string. Examples below.
hashPlusCount("###+") ➞ [3, 1]
hashPlusCount("##+++#") ➞ [3, 3]
hashPlusCount("#+++#+#++#") ➞ [4, 6]
hashPlusCount("") ➞ [0, 0]
Here is the code I came up with using regex.
const hashPlusCount = str =>
str === "" ? [0,0] :
[str.match(/\#/gi).length,
str.match(/\+/gi).length];
The code works fine on repl.it and outside editors. It even works on the code playground on edabit itself! But on the challenge page, it is returning " Cannot read property 'length' of null at hashPlusCount".
Any help in resolving this and helping me understand what's going on is appreciated.