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

156
Views
Merge sort based on number of values in arrays

I would like to understand how to use merge sort to sort arrays based on the number of values in each array.

let test = [
{
name: "a",
numbers: [1,2]
},{
name: "b",
numbers: [1,2,3]
},{
name: "c",
numbers: [5]

The 'a' has 2 numbers, the 'b' has 3 numbers and the 'c' has 1 number. So it should be sorte as follows, from high to low: b, a, c.

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

0

Just use the array sort with a compare function.
The function should substract the lengths of the numbers property of objects.
More info: Array.sort() on MDN

test.sort((a, b) => b.numbers.length - a.numbers.length)
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!