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!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Five steps for building a successful API-powered digital ecosystem

UML Quick Reference

Case Study on MongoDB

Learning Habits for SE Students

18 Precious Wedding Photo Ideas with Your Dogs

Text To Speech App For Mac

Super Staker Status Tool

Multi-Chain (Lend) Sneak Peek #1

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
HopeGiometti

HopeGiometti

More from Medium

635. Design Log Storage System

Quick Update — New Job Prep

Recursively Recurse with Recursion

Leetcode 167: Two Sum II Sorted Input Array