Solving Popular Algorithms: String Matching

I think the mayor needs help with that string!
words = ["mass", "as", "hero", "superhero"]
words = ["blue","green","bu"]
strMatching = (words) => {
let results = []

for (let i = 0; i < words.length-1; i++){
for (let j = i+1; j < words.length; j++) {
if (words[i].includes(words[j])) {
results.push(words[j])
}
}
}
return results
}
strMatching = (words) => {
let results = []

for (let i = 0; i < words.length-1; i++){
for (let j = i+1; j < words.length; j++) {
if (words[i].includes(words[j])) {
results.push(words[j])
} else if (words[j].includes(words[i])) {
results.push(words[j])
}
}
}
return results
}
strMatching = (words) => {
let results = []

for (let i = 0; i < words.length-1; i++){
for (let j = i+1; j < words.length; j++) {
if (words[i].includes(words[j]) && !results.includes(words[j])) {
results.push(words[j])
} else if (words[j].includes(words[i]) && !results.includes(words[i])) {
results.push(words[j])
}
}
}
return results
}
Kitty got the string!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store