1var beautySum = function (s) {2const len = s.length;34let ans = 0;5const freq = new Array(26).fill(0);67for (let i = 0; i < len; i++) {8freq[s[i].charCodeAt(0) - "a".charCodeAt(0)]++;9for (let j = i + 1; j < len; j++) {10freq[s[j].charCodeAt(0) - "a".charCodeAt(0)]++;11ans += minMaxDiff(freq);12}13freq.fill(0);14}1516function minMaxDiff(freq) {17freq = freq.filter((f) => f != 0);18return Math.max(...freq) - Math.min(...freq);19}2021return ans;22};