DEV Community

Sham Gurav
Sham Gurav

Posted on

3 1

#25 Guess The Output ???

⭐ Reply with correct answer & Bonus points for explanation ⚡

💡 Correct answer with detailed explanation will be updated in comments after 48 hours.

const numbers = [35, 2, 4, 11, 7];
numbers.sort();
console.log(numbers[2]);
Enter fullscreen mode Exit fullscreen mode

Top comments (6)

Collapse
 
westernal profile image
Ali Navidi

sort function is working fine with strings but for numbers it give us a wrong answer and the answer will be like this: [11,2,35,4,7] so numbers[2] = 35

Collapse
 
shamgurav96 profile image
Sham Gurav

Sure @lukeshiru . I'll make those changes.

Thanks a lot for feedback otherwise I wouldn't have known the issue.

Collapse
 
muhyilmaz profile image
MUHAMMED YILMAZ • Edited
  1. Not 7
Collapse
 
shamgurav96 profile image
Sham Gurav

definitely not 7 but do you know what it will log in console ???

Collapse
 
westernal profile image
Ali Navidi

Yes thank you🙏🏻

Collapse
 
gabrielmlinassi profile image
Gabriel Linassi

Interesting question, thanks. I thought it would be 7 but then I thought hold up wait a minute something ain't right, can't be that easy.

AWS Q Developer image

Your AI Code Assistant

Q Developer CLI agent provides a lightning-fast coding experience that can read and write files locally, call AWS APIs, run bash commands, or create code—all while adapting to your feedback in real-time.

Start coding for free

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay