-
-
Couldn't load subscription status.
- Fork 35
Description
Example case:
a = function () {}
b = function () {}
demand([a, b]).be.permutationOf([a, b]) // this passes
demand([b, a]).be.permutationOf([a, b]) // this failsThe 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]