如何在一个字符串中搜索第二个字符串中包含的所有单词?

Osc*_*nes 2 javascript string jquery

我需要string A根据它是否包含另一个单词中的所有单词来检查匹配string B- 无论顺序如何.

那么,让我们说string A是这样的:

one two three four five
Run Code Online (Sandbox Code Playgroud)

string B就是其中之一:

one two three // match!
one three two // match! (order doesn't matter)
one two six // NOT A MATCH! ('six' is not found in string A)
one two three four // match!
one two three four five // match!
one two three four five seven // NOT A MATCH! ('seven' is not found in string A)
Run Code Online (Sandbox Code Playgroud)

我怎样才能找到匹配,string A并且string B只有在string B找到每个单词时才会找到匹配string A(无论字符串中的单词顺序如何,也不管是否string A包含其他未找到的单词string B)?

我不知道jQuery是否有任何特殊功能可以帮助解决这个问题,或者我是否需要严格使用纯JavaScript?

str*_*ger 7

  1. 将字符串拆分为单词数组.
  2. 对于每个单词string A,分配obj[word] = true;.
  3. 对于每个单词string B,检查是否obj[word] === true;.如果没有,则返回false.
  4. 回归真实.

这应该是无足轻重的,可以转化为代码.