我正在尝试建立一个小的应用程序,可以在一个词中找到不同的音素单位。我有一组音素数据,如下所示:
export const consonants = [
{
consonantSound: 's',
spellings: [
{ spelling: 's', example: 'sun' },
{ spelling: 'ss', example: 'class' },
{ spelling: 'c', example: 'cell' },
{ spelling: 'ce', example: 'voice' },
{ spelling: 'house', example: 'se' },
{ spelling: 'scent', example: 'sc' },
],
},
{
consonantSound: 'sh',
spellings: [
{ spelling: 'sh', example: 'ship' },
{ spelling: 'ch', example: 'machine' },
],
},
[...]
]例如,对于单词laugh,我需要搜索数据集,直到找到匹配l、au、gh的拼写(这是该单词/l/ /ar/ f/的音素单位)。
我试过了,但这看起来很离谱,现在我很困惑。
export const phonemeCheck = (word) => {
for (let i = 0; i < word.length; i++) {
let chunk = word.slice(i)
for (let i = 0; i < consonants.length; i++) {
let consonantSpelling = consonants[i].spellings[0].spelling
console.log(chunk, consonantSpelling)
}
}
}我认为我需要实现的是这样的东西:
"l","la", "lau", "laug", "laugh", "a", "au", "aug", "augh", "u", "ug", "ugh", "g", "gh".想知道是否有人能提供一些指导?
发布于 2022-09-04 10:29:26
这是给块状部分的。如果这还不够,你能编辑你的问题来增加一个最小的例子和预期的输出吗?
const phonemeCheck = (word) => {
for (let i = 0; i < word.length; i++) {
for (let j = 0; j < word.length - i; j++) {
let chunk = word.substring(i, i + j + 1);
console.log(chunk);
}
}
}
phonemeCheck("abcd");
https://stackoverflow.com/questions/73597709
复制相似问题