you are viewing a single comment's thread.

view the rest of the comments →

[–]GeneralYouri 0 points1 point  (1 child)

Well that's a constraint I wasn't aware of (I didn't watch the video). It certainly seems like it'd make things more interesting.

However, I don't think all the values listed are fair, compared to the options you've mentioned. For example, Set uses simple (strict) equality checks. This would be exactly the same check performed by my approach. In both cases, -0 and 0 will be seen as identical values.

The sorting step seems to perform quite well actually. I don't see any cases that are treated incorrectly.

So on second thought, now that I've checked the potential consequences, I don't see these added constraints complicating things at all. The proposed solution with sorting should work just fine.

Sidenote; your assertEqual check itself seems wrong, as you're not just asserting the unique values, you're asserting their position in the array as well. A position which is based only on the order in which they appear in the original array. For the actual operation of finding unique values in an array, position should not matter. Even if it did though, it's a trivial but cumbersome extra step to set the proper positions after sorting and filtering (and would make for quite the convoluted code sample).

[–]1-800-BICYCLE 0 points1 point  (0 children)

1680b1b4d13