DEV Community

Sham Gurav
Sham Gurav

Posted on

#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.