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

103
Views
Dividir una matriz bidimensional

Tengo esta matriz bidimensional de tareas

 const graph = [ ['tie your shoes', 'put on your shoes'], ['put on your jacket', 'put on your shirt'], ['put on your shoes', 'put on your shorts'], ['put on your jacket', 'put on your shorts'], ['buy eggs from store', 'cook eggs'], ['heat up skillet', 'cook eggs'] ]

Necesito dividir este gráfico en dos matrices separadas si no tienen asociación entre sí. (es decir, ponerse los zapatos y cocinar huevos no tienen ninguna asociación/relación dentro del gráfico)

Cada matriz dentro del graph es una asociación de tareas. Se puede rastrear una asociación entre dos tareas si se pueden rastrear hasta una sola tarea común: ponerse la chaqueta se puede rastrear hasta ponerse los calcetines.

El resultado debería verse así

 const graph_1 = [ ['tie your shoes', 'put on your shoes'], ['put on your jacket', 'put on your shirt'], ['put on your shoes', 'put on your shorts'], ['put on your jacket', 'put on your shorts'] ] const graph_2 = [ ['buy eggs from store', 'cook eggs'], ['cook eggs', 'heat up skillet'] ]

No me preocupa clasificarlos en este momento, solo me preocupa dividirlos

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podría usar una combinación de bucles para verificar una matriz que contiene palabras clave.

 const graph = [ ['tie your shoes', 'put on your shoes'], ['put on your jacket', 'put on your shirt'], ['put on your shoes', 'put on your shorts'], ['put on your jacket', 'put on your shorts'], ['buy eggs from store', 'cook eggs'], ['heat up skillet', 'cook eggs'] ] // Keywords const clothes = ['shoes', 'jacket', 'shorts'] const foods = ['eggs', 'heat', 'skillet'] // Creating graph 1 const graph_1 = graph.filter(array => { return array.reduce((arr, str) => { clothes.forEach(item => { if (str.includes(item)) { arr.push(str) } }) return arr }, []).length }) // Creating graph 2 const graph_2 = graph.filter(array => { return array.reduce((arr, str) => { foods.forEach(item => { if (str.includes(item)) { arr.push(str) } }) return arr }, []).length }) console.log(graph_1) console.log(graph_2)

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!