5 kyu
Multi Level Sorting
197 of 200christianhammer
Loading description...
Sorting
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
random tests:
what is the expected behavior when some records do not have the sorting key ? this is not explained in the description
chai.config.truncateThreshold = 0
is missing in JavaScriptas mentionned below, the example in the description is wrong: the result is sorted by name, whereas the
order
specifies sorting by job and age.was probably meant to be "The AJAX request does not support sorting"
Real-life kata!
JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this
done at some point
Very useful kata for real-applications.
For your example in the instructions, you're showing the records sorted by name, instead of by job & age like shown in the order array.
Test-Issue (Will be closed in a few minutes.)
Closed
This is very cool task, but the tests were broken. So I did fix them.
Did you uncheck the option "Allow Contributors"?
I am not able to do that.
But how did you fixed the tests?
As others have said, this is unsolvable. Please fix final test "order" parameter format.
its fixed right now
Great! Thanks @gkucmierz!
I could solve it! So I close this issue.
Kata is unsolvable. In description it says "order" is array [{'key':'job', 'direction':'ascending'}], but in tests "order" is an object like {'job':'ascending'}. Javascript doesn't guarantee that 'for ... in' works in same order in which fields have been defined. So there is no way to determine priority of sort keys.
its fixed right now
Great! Thanks @gkucmierz!
I could solve it! So I close this issue.
order-items are not the same in
Your test-cases
and"Final"
(submit) ones :...in
Your
test-cases,...in Final test-cases.
its fixed right now
This comment has been hidden.
Am getting "Initial Solution does not have valid code. The code should not pass the kata test cases" when trying to re-publish. Solution validates and show green. Can anybody explain what this message hints at?
It's talking about the "Initial Solution". It's in the tab next to the "Solution" tab. It's the code which is given to the coder when they start the kata. The system is saying that that code already passes the tests, effectively giving the coder the answer right off.
Thanks :)
I see you all have ranked this to 6 or 7 kyu. However, the "Sort arrays - 3" by ineiti is ranked 5 kyu. Since my kata is a generalisation of the same problem, I think it should rank higher than "Sort arrays - 3", therefore I set it to 4. However, kyu 5 state "Custom sorting" - so I find it should be in range of 5 to 4...
Besides the testing issues listed above, there's a much bigger problem with this kata: you cannot guarantee the order of the properties on an object.
This means that iterating over the properties in
could return either
job
thenage
, orage
thenjob
. Instead, you need to pass in some sort of ordered structure, such as an array or a string. Any of these would be acceptable:Ha, you are right and the format will be the first you list. My impression of key ordering = insertion/creation order was "only" based on three years of working experience with the Safari, Opera, FireFox, Chrome and IE. From IE7 and on, FF3.6 and on and on the last two years of versions of the other browsers all follow the "insertion order"... Just read the spec which clearly state no ordering can be expected... Sigh...
Fixed now - and soon your "solution" should be invalidated. Don't know if "sorry" is the right word here ;-)
You example test case is still showing the old format. You need to update the order variable.
True, just fixed. Thanks :)
This comment has been hidden.
No, I just created a random "order" - including an empty object which will lead to no sorting at all. Have a few ideas how to circumvent this :) Thanks for info.
This comment has been hidden.
Of course, this should no be possible. I'll try to invalidate your solution ;-) Thank you for the feedback.
This comment has been hidden.
This comment has been hidden.
OK, now found the bug in my test case comparing user solution output with .... ehm... user solution output! Duh! No wonder everything worked fine :)
This comment has been hidden.
You are right, I will see if I can invalidate your solution ;-) Thank you.
A nice little kata to get the brain going. It seems the example test fixture you've given us isn't right, though. My code passed the regular tests, but not that example test.
The test fixture is more elaborate and generate app 40 random records (even having multiple fields with the same value) and a "random" ordering.