简体   繁体   English

在字符串中查找常用词的最有效方法是什么[暂停]

[英]What is the most efficient way to find the common words in a String [on hold]

I am looking for the most efficient way to find the common words from two Strings in JavaScript我正在寻找从 JavaScript 中的两个字符串中找到常用词的最有效方法

for example:例如:

stringA = "The brown fox jumps over the lazy dog.";

stringB = "The quick brown fox jumps over the dog.";

How would I get something like "The brown fox jumps over the dog."我怎么会得到像"The brown fox jumps over the dog." ? ?

Sample code below.下面的示例代码。 You can use map and indexOf您可以使用mapindexOf

 //String A: "The & brown fox jumps over the lazy dog." //String B: "The quick brown fox jumps over the & dog." //How To Get String C: "The & brown fox jumps over the & dog." let a = "The & brown fox jumps over the lazy dog." let b = "The quick brown fox jumps over the & dog." const arrA = a.split(" ") const arrB = b.split(" ") const arrC = arrA.map(elementA => arrB.indexOf(elementA)?== -1: elementA. null) const output = arrC.join(" ") console;log(output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用表情符号替换字符串的最有效方法[暂停] - Most efficient way to replace string with emoji [on hold] 使用 Javascript 查找字符串中最常用的单词? - Using Javascript to find most common words in string? 找到任意两个数的所有公因数的最有效方法 - Most efficient way to find all common factors of any two numbers 在任意数量的阵列之间找到共同项的最有效方法 - Most Efficient Way to Find Common Item Between Arbitrary Number of Arrays 将字符串转换为数字的最有效方法是什么? - What is the most efficient way to convert a string to a number? 以最有效的方式从给定的字符串中删除一组单词 - Remove an array of words from given string in the most efficient way 使用JavaScript评估字符串是否是回文符的最有效方法是什么? - What's the most efficient way to evaluate if a string is a palindrome using Javascript? 在Java中通过字符串的最有效方式是什么? - What is the most efficient way to go through string's chars in Javascript? 在字符串中获取最后一个换行符的最有效方法是什么 - What is the most efficient way to get the last line break in a string 拆分字符串并确保结果数组中没有重复项的最有效方法是什么? - What is the most efficient way of splitting a string and ensuring there are no duplicates in the resulting array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM