I'm trying to rewrite this frequency finding program in Javascript. Here is the Java code:
public class frequency {
public static void main(String[] args){
String S = "Temple University";
int[] p = new int[256];
for (char c :S.toCharArray()) {
p[c]++;
System.out.println(c +" shows up "+p[c] + " times");
}
Output:
T shows up 1 times
e shows up 1 times
m shows up 1 times
p shows up 1 times
l shows up 1 times
e shows up 2 times
shows up 1 times
U shows up 1 times
n shows up 1 times
i shows up 1 times
v shows up 1 times
e shows up 3 times
r shows up 1 times
s shows up 1 times
i shows up 2 times
t shows up 1 times
y shows up 1 times
However, my JavaScript implementation doesn't work at all:
function frequency(){
s = "Temple University";
str = s.split('');
p = [];
p.length = 256;
console.log("start");
for(c in str){
p[c]++;
console.log("inside" + c);
console.log(String.fromCharCode(c) + " shows up " + p[c] + "times");
}
}
It's late I've been trying to figure out why this JavaScript code is not working so I'm sorry if this post seems unpolished.