I'd like to sort numbers and strings like this article: Sort strings and numbers in Ruby
And I prepared the following method to compare values.
# This method is expected to work Ruby's `<=>`.
compare: (x, y) ->
if x < y then -1 else if x > y then 1 else 0
But JavaScript's comparison works different from Ruby's one.
x = [1, 11]
y = [1, 2]
compare(x, y)
# it expected to return 1 (means [1, 11] > [1, 2])
# but it returns -1 (means [1, 2] > [1, 11])
Though 11 is obviously greater that 2, array's second value seems not to be compared correctly.
Could you tell me what's wrong?
x < yworks.