-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
permutationOf
is not reliable for arrays containing non-primitive values
#38
Comments
Hey again. You're quite right. Thanks for bringing this up. I agree wrt to JavaScript, the language. So many abstractions lacking that have been around for decades in the programming language space. Anywho, due to lack of stable sort order, I think the |
It looks like none of the other popular libs has a expect(a.length).to.be(b.length)
b.forEach(v => expect(a).to.contain(v)) Its main drawback is quadratic time complexity, assuming that |
Fixes moll#38 This should make `permutationOf` work correctly for arrays containing values other than strings, numbers and booleans.
Example case:
The second assertion fails with
AssertionError: [null,null] must be a permutation of [null,null]
.This problem is caused by array sort function converting values to strings by default and using them for deciding what goes first.
[rant]
Unfortunately, in JavaScript, for most types of values (like e.g. functions, objects, arrays, and recently symbols, maybe also regexps) there is no defined order. IMO, this is one of the reasons JS sucks, because it unnecessarily forces us into linear time complexity (or some dirty tricks), where otherwise logarithmic would be possible, or quadratic instead of linear. At least there is
Map
that helps alleviate the problem a bit.[/rant]
The text was updated successfully, but these errors were encountered: