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

Introducing Ragtag Web Squads

How to Setup Docker Private Registry on Ubuntu 20.04

docker-version-output-linux

How to build Parking Mobile App | PowerApps Tutorial | Step by step

How to build Parking App

Apigee 101: Fault Handling

proxies

App Tracking Transparency Framework in Swift and iOS 14.5

Document generation of Akka-HTTP using Swagger

build

5 ways to speed up your Lambda function

“If it turns out that this is incurable, would you marry me?”

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

Task scheduler (leetcode)

What is Reactive Programming? | Interview basics

CodeSignal Solutions — Arrays

Frog Jump