I am working on a Javascript application and have run into a problem that I can’t solve. I have to write a function that takes a string and returns an object where the property names are characters and the values are how often that character appears in the string. What I have written so far is:
function getFrequencies(str) {
var holder = str;
var ticker = str;
var i = 0;
var j = 0;
var result = [];
while (i < holder.length && j < ticker.length) {
if (holder.charAt(i) < ticker.charAt(j)) {
i++;
}
else if (ticker.charAt(j) < holder.charAt(i)) {
j++;
}
else {
result.push(holder.charAt(i));
i++;
j++;
}
}
return result;
}
If there is someone who can help me figure out how to make this work correctly and tell me what I am doing wrong I would greatly appreciate it.
Or