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

140
Views
sort order should be by date, then alphabetical (so all active at top A-Z, then all inactive at bottom A-Z)

Image
i have to show the list in sorting order with respect to signature date, if signature date is not past dated and if there is no date for signature date then it is considered as active record(sort order should be by status, then alphabetical (so all active at top A-Z, then all inactive at bottom A-Z). I have done sorting based on name but not able to push inactive signature dates to the end. I have attached DEMO as well.

const  employee = [
{
  name: 'jpat',
  signatureDate: '',
  businessType: 12346,
  originalFileName: 'hello.xls',
  agentW9id: 11,
  fileName: 'hello.xls',
  agentCode: 0,
  class: '',
  status: '',
},
{
  name: 'jcar',
  signatureDate: '09/10/2021',
  businessType: 12346,
  originalFileName: 'test.xls',
  agentW9id: 12,
  fileName: 'test.xls',
  agentCode: 0,
  class: '',
  status: '',
},
{
  name: 'Test',
  signatureDate: '09/23/2020',
  businessType: 12346,
  originalFileName: 'test.xls',
  agentW9id: 13,
  fileName: 'test.xls',
  agentCode: 0,
  class: 'inactive',
  status: 'Inactive',
},
{
  name: 'newTest',
  signatureDate: '10/9/2020',
  businessType: 12346,
  originalFileName: 'test.xls',
  agentW9id: 13,
  fileName: 'test.xls',
  agentCode: 0,
  class: 'inactive',
  status: 'Inactive',
},
{
  name: 'abc',
  signatureDate: '10/29/2021',
  businessType: 12346,
  originalFileName: 'test.xls',
  agentW9id: 13,
  fileName: 'test.xls',
  agentCode: 0,
  class: '',
  status: '',
},
{
  name: 'djhfj',
  signatureDate: '',
  businessType: 12346,
  originalFileName: 'test.xls',
  agentW9id: 13,
  fileName: 'test.xls',
  agentCode: 0,
  class: '',
  status: '',
},
  ];
  
console.log(employee.sort((a, b) => (a.name > b.name ? 1 : -1)));

DEMO

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

0

Okay, updated code,

  1. break into objects based on status ( active and inactive)
  2. Sort each based on name and append back together

Working code below and Sandbox

Reult image enter image description here

const employee = [{
    name: 'jpat',
    signatureDate: '',
    businessType: 12346,
    originalFileName: 'hello.xls',
    agentW9id: 11,
    fileName: 'hello.xls',
    agentCode: 0,
    class: '',
    status: '',
  },
  {
    name: 'jcar',
    signatureDate: '09/10/2021',
    businessType: 12346,
    originalFileName: 'test.xls',
    agentW9id: 12,
    fileName: 'test.xls',
    agentCode: 0,
    class: '',
    status: '',
  },
  {
    name: 'Test',
    signatureDate: '09/23/2020',
    businessType: 12346,
    originalFileName: 'test.xls',
    agentW9id: 13,
    fileName: 'test.xls',
    agentCode: 0,
    class: 'inactive',
    status: 'Inactive',
  },
  {
    name: 'newTest',
    signatureDate: '10/9/2020',
    businessType: 12346,
    originalFileName: 'test.xls',
    agentW9id: 13,
    fileName: 'test.xls',
    agentCode: 0,
    class: 'inactive',
    status: 'Inactive',
  },
  {
    name: 'abc',
    signatureDate: '10/29/2021',
    businessType: 12346,
    originalFileName: 'test.xls',
    agentW9id: 13,
    fileName: 'test.xls',
    agentCode: 0,
    class: 'inactive',
    status: 'Inactive',
  },
  {
    name: 'djhfj',
    signatureDate: '',
    businessType: 12346,
    originalFileName: 'test.xls',
    agentW9id: 13,
    fileName: 'test.xls',
    agentCode: 0,
    class: '',
    status: '',
  }
];

var inactive = [],
  active = [];
employee.forEach((item) => {
  if (item.status == 'Inactive')
    inactive.push(item);
  else
    active.push(item);
});



inactive.sort(function(a, b) {
  if (a.name.toLowerCase() < b.name.toLowerCase()) {
    return -1;
  }
  if (a.name.toLowerCase() > b.name.toLowerCase()) {
    return 1;
  }
  return 0;
})

active.sort(function(a, b) {
  if (a.name.toLowerCase() < b.name.toLowerCase()) {
    return -1;
  }
  if (a.name.toLowerCase() > b.name.toLowerCase()) {
    return 1;
  }
  return 0;
})


var sortedArray = active.concat(inactive);

console.log(sortedArray);

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!