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

179
Views
Dynamic tree algorithm using JS

-init Data

{
sport: ['s_1', 's_2', 's_3'],
date: ['d_1', 'd_2'],
category: ['c_1']
}
  • Input data (dynamic with fields)

['sport', 'date'] or ['sport', 'date', 'category']

  • Output data

If input data = ['sport', 'date']

: output have to show below.

[
's_1',
's_1|d_1',
's_1|d_2',
's_2',
's_2|d_1',
's_2|d_2',
's_3',
's_3|d_1',
's_3|d_2'
]

If input data = ['sport', 'date', 'category']

: output have to show below.

['s_1',
's_1|d_1',
's_1|d_1|c_1',
's_1|d_2',
's_1|d_2|c_1'
's_2',
's_2|d_1',
's_2|d_1|c_1',
's_2|d_2',
's_2|d_2|c_1',
's_3',
's_3|d_1',
's_3|d_1|c_1',
's_3|d_2',
's_3|d_2|c_1'
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a recursive generator function:

var data = {sport: ['s_1', 's_2', 's_3'], date: ['d_1', 'd_2'], category: ['c_1']}
function* combos(d, c = []){
    if (c.length > 0){
       yield c.join('|')
    }
    if (d.length > 0){
        for (var i of data[d[0]]){
            yield* combos(d.slice(1), [...c, i])
        }
    }
}
console.log([...combos(['sport', 'date'])]) 
console.log([...combos(['sport', 'date', 'category'])]) 

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!