JavaScript function to automatically count consecutive letters in a string
问题 I am attempting (unsuccessfully) to write JavaScript function LetterCount to count the consecutive letters in a string (and not the total number). Ideally: LetterCount("eeeeeoooohhoooee") = [["e", 5],["o",3],["h",2],["o",3],["e",2]] The following code attempts to count the number of consecutive letters in a string only when I already know what they are: function LetterCount(str) { for (var i=0; i<str.length;i++) { var arr1=[]; arr2=[]; arr3=[]; arr4=[]; arr5=[]; var e=0; o=0; h=0; o2=0; e2=0;