簡體   English   中英

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

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

我正在尋找從 JavaScript 中的兩個字符串中找到常用詞的最有效方法

例如:

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

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

我怎么會得到像"The brown fox jumps over the dog." ?

下面的示例代碼。 您可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM