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

154
Views
¿Cómo generar una estructura de árbol analizando la cadena?

La respuesta original de la API es la siguiente

 org = [ { title: "New", count: 1 }, { title: "Parent::Child::GrandChild", count: 0 }, { title: "Parent::Child", count: 0 }, ]

¿Cómo puedo convertir un nuevo objeto analizando el título de la respuesta anterior?

 newObtj = [ { title: "New", count: 1, child: [] }, { title: "Parent", count: 0, child: [ { title: "Child", count: 0, child: [{ title: "GrandChild", count: 0, child: [] }] } ] }, { title: "Parent", count: 0, child: [{ title: "Child", count: 0, child: [] }] }, ]

¡Gracias de antemano!

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

0

Debe tomarse el tiempo para pensar cómo desea que se estructure su nuevo objeto. Para comenzar, así es como tomaría una cadena delimitada y construiría un objeto a partir de ella:

 const treeString = 'Parent::Child::GrandChild'; // input string const treeParts = treeString.split('::'); // split into levels var tree = []; // will contain the final tree for this input var count = 0; // input count var child = []; // variable to hold children we have processed // loop through input from lowest level (GrandChild) up to top level (Parent) for (var i = treeParts.length - 1; i>=0; i--) { // Create a child element (for top level this will be added to Tree) child = { title: treeParts[i], count: count, child: [ child ] }; } // Finally add to tree tree.push(child);

Probablemente querrá convertir esto en una función y llamarla para cada elemento en su objeto original.

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!