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

222
Views
Implementing tree sorting without creating extra function

I have a function which sorts my data tree according to it's items order

  const itemSorter = (items) =>
  items
    .map((item) => (item?.children ? { ...item, children: itemSorter(item.children) } : item))
    .sort((i1, i2) => i1.order - i2.order);

 sortItems(dataTree);

So my question is:
Is it possible to implement the same logic without creating function itemSorter, just start with

return dataTree.map(.... and so on) 

or that's impossible when we use recursion and we always need the name?

about 4 years ago · Juan Pablo Isaza
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!