function getASCIIFrequency(str) {
const frequencyTable = new Array(128).fill(0);
for (let i = 0; i < str.length; i++) {
frequencyTable[str.charCodeAt(i)]++;
}
return frequencyTable.reduce((accumulator, count, index) => {
if (count > 0) {
accumulator[String.fromCharCode(index)] = count;
}
return accumulator;
}, {});
}
const str = "javascript c c++ c# java python php";
const asciiFrequency = getASCIIFrequency(str);
console.log(asciiFrequency);
/*
run:
{
' ': 6,
'#': 1,
'+': 2,
a: 4,
c: 4,
h: 2,
i: 1,
j: 2,
n: 1,
o: 1,
p: 4,
r: 1,
s: 1,
t: 2,
v: 2,
y: 1
}
*/