首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据数据集检查字符串中字母的组合

根据数据集检查字符串中字母的组合
EN

Stack Overflow用户
提问于 2022-09-04 07:58:40
回答 1查看 23关注 0票数 0

我正在尝试建立一个小的应用程序,可以在一个词中找到不同的音素单位。我有一组音素数据,如下所示:

代码语言:javascript
复制
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/的音素单位)。

我试过了,但这看起来很离谱,现在我很困惑。

代码语言:javascript
复制
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)
    }
  }
}

我认为我需要实现的是这样的东西:

代码语言:javascript
复制
"l","la", "lau", "laug", "laugh", "a", "au", "aug", "augh", "u", "ug", "ugh", "g", "gh".

想知道是否有人能提供一些指导?

EN

回答 1

Stack Overflow用户

发布于 2022-09-04 10:29:26

这是给块状部分的。如果这还不够,你能编辑你的问题来增加一个最小的例子和预期的输出吗?

代码语言:javascript
复制
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");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73597709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档