Question 4
Back to Exercise
Without a compare function, how does [25, 100, 8].sort() order the numbers?
- A Numerically ascending: [8, 25, 100]
- B Numerically descending: [100, 25, 8] because of size
- C It leaves them unchanged
- D It converts them to strings and compares them character by character: [100, 25, 8] Correct
Correct Answer: Option D
"100" < "25" < "8" as strings, because "1" < "2" < "8". The descending-looking result is a coincidence of string order. Use sort((a, b) => a - b).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!