Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Restrictive filtering array in Javascript/TypeScript for a relationship path problem

I have a filtering problem I am trying to solve in TS/JS and stuck.

I want to filter an array with possible paths with an array of keywords. And it should not have any thing else other than these keywords.

let paths = ['Domain.travelers', 'Domain.travelers.products', 'Domain.travelers.remarks.products', 'Domain.products', 'Domain.vehicle.travelers.products'];
    
let keywords = ['travelers', 'products'];

When filter is applied, it should only return:

['Domain.travelers', 'Domain.travelers.products', 'Domain.products']
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can find docs about functions I used here:

  • Array - MDN
  • String - MDN

const paths = ['Domain.travelers', 'Domain.travelers.products', 'Domain.travelers.remarks.products', 'Domain.products', 'Domain.vehicle.travelers.products'];

const keywords = ['travelers', 'products'];

const results = paths.filter(path =>
  path.split('.').slice(1).every(
    pathPart => keywords.includes(pathPart)
  )
);

console.log(results);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!