count consecutive characters in a string javascript