// JavaScript Document
var person = prompt("GIVE INPUT", "");
var count = 0;
var array = person.split(",");
var freq = [];
var words = [];
//freq.fill(0);
//words.fill("");
//window.alert(freq[0]);
var i = 0, j = 0;
while (array.length > 0) {
var temp = array[0];
while (j < array.length) {
if (temp == array[j]) {
count = count + 1;
array.splice(j, 1);
//console.log(array);
j = 0;
}
else {
j = j + 1;
}
}
freq[freq.length] = count;
count = 0;
words[words.length] = temp;
}
window.alert(freq + "\n" + words);
的问题是,每当我运行出现一个无限循环,并表示,我无法找到错误请尽可能帮助没有输出。此代码用于查找输入字符串中的单词的频率,用逗号分隔单词。谢谢你。
什么是你的脚本,该怎么办? – j08691
在调试器中逐句通过代码总是有用的。你会很容易地知道发生了什么。 –
计算字符串中用逗号分隔的单词的频率 - @ j08691 – Vishal