4 ms·
Great example of how the lack of custom value types really hurts JavaScript as a functional programming language. > [ 1, 2, 3 ] === [ 1, 2, 3 ] false
by de_keyboard 5y ago
Great example of how the lack of custom value types really hurts JavaScript as a functional programming language.
> [ 1, 2, 3 ] === [ 1, 2, 3 ]
false
Ridiculous!
- bpierre 5y agoTuples are coming to JS: https://github.com/tc39/proposal-record-tuple#tuple https://github.com/tc39/proposal-record-tuple#tuple
- de_keyboard 5y agoThis would be such a huge improvement (and records too)!
- ThePadawan 5y agoI still get bitten by > [] == [] < false sometimes. And that's with two equal signs, not three!
- phist_mcgee 5y agoTwo separate references to two separate arrays equaling false? What's the problem?
- ThePadawan 5y agoJS has a very "unique" opinion that that is how that should be interpreted. Given the same input as above: Python says True. Ruby says true. JS says false. And otherwise, JS is quite lenient with not interpreting the input like you describe it when using "==": > [] == 0 < true > [] == false < true
- de_keyboard 5y agoWhen doing functional programming, immutable lists with value comparison are what you want. However with JS, you only get mutable arrays with reference equality out-of-the-box. You can use a library, as others have point out, but then your code gets very noisy.
- addandsubtract 5y agounderscore/lodash is pretty much the go-to extension to JS. > _.isEqual([ 1, 2, 3 ], [ 1, 2, 3 ]) true