[英]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
您可以使用map
和indexOf
//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.