Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
.
Something is wrong with the typescript tests. It keeps expecting an empty array, when it should expect the duplicates which are similar to the provided test case. Here's the result I get. Am I missing something?
This comment is hidden because it contains spoiler information about the solution
Thanks. I already understood the sort method. I was unaware that zero was considered falsy, since I foolishly assumed all numbers would evaluate to truthy. It's clear to me now. Thanks again.
Yes, negative numbers are truthy and that is necessary for this to work.
Both compareStats and sortStats list comparisons in priority order. The or "||" operator falls through to the next comparison only when the previous result was 0 (falsey), meaning the two items were considered equal by the previous comparison. A non-zero value (negative or positive) indicates we already know the relative order of the two items and don't need to look at further comparisons.
The result can then be used by the array sort method to actually sort the items. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Love this solution. Would you mind explaining how the compareStats and sortStats functions work? I thought that negative numbers would evaluate to truthy, so I'm having trouble following the logic.
Yeah, that's my bad. I just resubmitted the previously failing Typescript version and it worked. But I'm new here and don't know how to close an issue.
There is no issue, 15 people solved the kata! And so did you! Next time close the issue, when you can solve the kata and see yourself, that there is no issue!
This comment is hidden because it contains spoiler information about the solution