1var appealSum = function (s) {2let ans = 0,3n = s.length;4let lastIndex = Array(26).fill(-1);5for (let i = 0; i < n; i++) {6let charcode = s.charCodeAt(i) - 97;7let lastIdx = lastIndex[charcode];8ans += (n - i) * (i - lastIdx);9lastIndex[charcode] = i;10}11return ans;12};