我正在从事一个项目,该项目要求我返回在输入框中输入的文本的 Flesch 可读性索引。公式如下:
206.835-85.6(number of syllables / number of words)-1.015(number of words / number of sentences)
我已经知道如何计算单词数,并且很确定我知道如何计算句子数,但我不知道如何计算音节数。
这是我得到的关于什么可以算作一个音节的信息:
Each group of adjacent vowels (a, e, i, o, u, y) counts as one syllable.
Each word has at least one syllable even if the above rule gives it a count of 0.
有人愿意为我指明正确的方向吗?
更新 我已经编写了一些代码,但无法使其正常工作。我发布了一个指向我正在处理的 jsfiddle 的链接,作为对下面的答案以及我遇到的问题的评论。如果有人愿意查看它并看看您是否可以帮助我弄清楚我做错了什么(除此之外很可能有更有效的方法),我们将不胜感激。
最佳答案
伪代码:
for each letter in word:
if letter is vowel, and previous letter is not vowel or this is the first letter, increment numSyllables
if numSyllables is 0, set numSyllables to 1
您可以使用 bool 值作为标志来确定前一个字母是否为元音字母。
遍历单词中的每个字母:
var word = "test",
i;
for(i = 0; i < word.length; i++) {
console.log(word[i]);
}
关于javascript - 使用 Javascript 计算段落中的音节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27451194/