7 kyu
Return a sorted list of objects
4,134 of 5,654NotBobTheBuilder
Loading description...
Arrays
Sorting
Fundamentals
View
Career Accelerator
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.
python new test framework is required. updated in this fork
Approved
python fork with new test framework
Superceded by above
Tests are missing
JS: Fixed some time ago.
This comment has been hidden.
No example test for Javascript
Haskell expects ascending sort, which contradicts the description.
Haskell fork that fixes the sort order to match the description.
in python, there were no instruction what to do if duplicate.
In Python like in any other language, there's nothing special to do in case of duplicates, so no instruction is needed.
This comment has been hidden.
No sample tests in JS
JS Node 18. should be enabled
Fixed some time ago, in this fork
This comment has been hidden.
I'd say Haskell has random tests. Expected values are unpredictable for the second and third
it
.Can you provide some example of sort_key, without it task is a bit obscure
This comment has been hidden.
This comment has been hidden.
a.sortBy
isa['sortBy']
rather thana[sortBy]
.Output tests - Unknown error; output - Expected: [{"a":3,"b":40},{"a":1,"b":12},{"a":2,"b":2}], instead got: [{"a":2,"b":40},{"a":3,"b":12},{"a":1,"b":2}]. In the opera-console the result of sorting the array is correct.
What could be the problem?
Haskell instructions ask for descending order but tests are ascending.
I can't access the array property by list[0]. It's undefined. Also, x is passed by to sortBy which doesn't seem to be one of the object properties.
You should specify if it's OK to alter the list in-place or if a new copy should be created. The default JS sort function will sort an array in-place, which can be surprising. But it also means that it doesn't need to return anything. It's perfectly valid to say
var l = [3,2,1].sort(); assert(l[0] === 1)
, because it mutatesl
rather than sorting into a new collection.Agreed. I was having it edit the array in-place like the JS .sort() and my tests passed but the "submit" tests failed. It took me a minute to figure out why.
If you require to sort by any attribute, you should also add a test case for another attribute than only
a
.I agree, at least a test case on attribute b should be present.
Test case for b has just been added :)
Isn't the sample list sorted in ascending order?
It took me a minute to realize the description said to sort the list in descending order, when the example shows this as the sorted list:
When it should be:
Agreed... I wrote my own tests from the example and then failed when I attempted to submit.
Oops! I initially had it as ascending but then changed everything except the example... d'oh!
That's fixed now :)
VERY minor comment: to me, it makes more logical sense for the list of objects to be the first function argument, and then the sortBy property name would be the second. Dunno why.
Agree with this point. Data as the first input and then sortBy as the second.