计算变量中使用的特定单词?

conye9980

目前正在从事 CodeAcademy JS 项目。

let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side.  An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson.  Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';

let overusedWords = ['really', 'very', 'basically'];

问题是“您想让程序的用户知道他们使用了这些过度使用的词多少次。”

努力获得它,提示是使用 If Else 语句,但不确定如何准确。

edkeveked

let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side.  An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson.  Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';
var overusedWords = ['really', 'very', 'basically'];

var used = {};
story.split(/[\s,]+/).forEach(item => {
    if (overusedWords.indexOf(item) >= 0) {
        if (!used[item]) {
            used[item] = 1
        }
        else {
         used[item] = used[item]+ 1   
        }
    }
});


console.log(JSON.stringify(used));

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用jQuery计算特定单词

来自分类Dev

使用熊猫计算不包含特定单词的文章数

来自分类Dev

使用awk计算文本中特定单词的实例

来自分类Dev

使用熊猫计算不包含特定单词的文章数

来自分类Dev

在熊猫中使用Regex提取特定单词

来自分类Dev

使用SpannableStringBuilder在android中使特定单词可点击

来自分类Dev

在html中使用<p>元素的特定单词

来自分类Dev

在熊猫中使用Regex提取特定单词

来自分类Dev

计算ArrayList <String>上的特定单词

来自分类Dev

如何计算包含特定单词的文档?

来自分类Dev

计算句子中的特定单词

来自分类Dev

删除变量中的特定单词

来自分类Dev

在sql oracle中使用regexp_substr在特定单词之后获取单词

来自分类Dev

使用CSS对特定单词使用分词

来自分类Dev

使用Regex.Matches计算字符串中的特定单词时出错

来自分类Dev

PHP使用preg_match_all搜索并计算特定单词

来自分类Dev

使用Regex.Matches计算字符串中的特定单词时出错

来自分类Dev

使用python和xlrd计算Excel工作表中特定单词的出现次数

来自分类Dev

计算特定单词的出现次数,并使用该计数更新输入文件的页脚

来自分类Dev

使用Bash脚本获取特定单词

来自分类Dev

如何在Perl中使用Excel在特定单词中应用斜体格式

来自分类Dev

如何在Ubuntu终端中使用grep从txt文件中提取特定单词

来自分类Dev

在Java中使用regexp替换字符串时如何跳过特定单词

来自分类Dev

计算句子haskell中特定单词的出现

来自分类Dev

Java:计算特定单词的频率并写入文件

来自分类Dev

计算其他数组中的特定单词

来自分类Dev

计算R中的特定单词频率

来自分类Dev

如何计算txt文件中特定单词出现的行数?

来自分类Dev

如何计算特定单词在列中出现的次数?

Related 相关文章

  1. 1

    使用jQuery计算特定单词

  2. 2

    使用熊猫计算不包含特定单词的文章数

  3. 3

    使用awk计算文本中特定单词的实例

  4. 4

    使用熊猫计算不包含特定单词的文章数

  5. 5

    在熊猫中使用Regex提取特定单词

  6. 6

    使用SpannableStringBuilder在android中使特定单词可点击

  7. 7

    在html中使用<p>元素的特定单词

  8. 8

    在熊猫中使用Regex提取特定单词

  9. 9

    计算ArrayList <String>上的特定单词

  10. 10

    如何计算包含特定单词的文档?

  11. 11

    计算句子中的特定单词

  12. 12

    删除变量中的特定单词

  13. 13

    在sql oracle中使用regexp_substr在特定单词之后获取单词

  14. 14

    使用CSS对特定单词使用分词

  15. 15

    使用Regex.Matches计算字符串中的特定单词时出错

  16. 16

    PHP使用preg_match_all搜索并计算特定单词

  17. 17

    使用Regex.Matches计算字符串中的特定单词时出错

  18. 18

    使用python和xlrd计算Excel工作表中特定单词的出现次数

  19. 19

    计算特定单词的出现次数,并使用该计数更新输入文件的页脚

  20. 20

    使用Bash脚本获取特定单词

  21. 21

    如何在Perl中使用Excel在特定单词中应用斜体格式

  22. 22

    如何在Ubuntu终端中使用grep从txt文件中提取特定单词

  23. 23

    在Java中使用regexp替换字符串时如何跳过特定单词

  24. 24

    计算句子haskell中特定单词的出现

  25. 25

    Java:计算特定单词的频率并写入文件

  26. 26

    计算其他数组中的特定单词

  27. 27

    计算R中的特定单词频率

  28. 28

    如何计算txt文件中特定单词出现的行数?

  29. 29

    如何计算特定单词在列中出现的次数?

热门标签

归档