Example:
[42] == [42]
The result of the comparison gives different results:
CS/JS: false
Ruby: true
On the other hand:
42 == 42
gives the result:
CS/JS: true
Ruby: true
What is the reasoning behind this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The other answerers have done a good job of explaining the JavaScript/CoffeeScript equality semantics. (CoffeeScript’s
==compiles to JavaScript’s stricter===, but that makes no difference in this case.)The Ruby case is more complex: Everything in Ruby is an object, and so every object has a
==method which, in principle, could do anything. In the case of arrays, it looks at the other array, checks if it has the same length, and then checks ifx == yfor eachxin itself andyin the other array.If you want to emulate the Ruby behavior, it’s quite simple to write a function to do so: