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

189
Views
Why an array cannot be sorted in both ascending and descending in a single block of code/function?

Why do ascending and descending arrays give the same output? Anyone can solve this?

function isSortedAndHow(arr) {
  let asc = arr.sort((a, b) => a - b); // Ascending order , yes
  let dsc = arr.sort((a, b) => b - a); // descending array, yes

  if (arr == asc) {
    console.log("Ascending , Yes");
  } else if (arr == dsc) {
    console.log("Descending , Yes");
  } else {
    console.log("No");
  }
}
isSortedAndHow([25,20,15,30,35]);
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!