7 kyu
Sorting Dictionaries
3,548 of 5,322cmgerber
Loading description...
Sorting
Lists
Fundamentals
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.
I think it would be nice to add cleaner differentiation between keys and values.
If you look at example/sample below, it does not really add much to the description. What goes first, key or value? What do we sort by? You can answer these questions by reading the description, but this defeats the purpose of example.
I think something like this would be a lot easier to read and actually complement the text:
python new test framework + random tests are required. updated in this fork
Approved
javascript should have tests with strings as values, many solutions are only handling number comparison
This comment has been hidden.
Done in latest fork
JS version update
This should be 6 or 5 kyu, this one is difficult to solve 😨
This comment has been hidden.
Javascript version of Kata could do with random test cases as well as fixed ones; keep that in mind when authoring future Kata :)
This comment has been hidden.
That is probably because you return the wrong type.
OrderedDict([]) != []
.Thanks! :)
This comment has been hidden.
I enjoyed this kata; it's an interesting problem, so well done on that. The description was a little sparse, however, with some of the more nuanced edge-cases not mentioned anywhere:
These were a little counter-intuitive (at least for me), so having them explicitly said up-front will save people a lot of headscratching and guesswork ;P
Keys in Javascript are always strings, not numbers. In light of this, I'm going to argue that requiring numbers in the output is wrong. They should be strings.
dict[1]
anddict["1"]
are the exact same thing, because1
has to be implicitly cast into a string before it can be used as an array index. That's also why JS doesn't automatically take the nearest integer or floor when you writedict[1.5]
-1.5
is cast into a string, and any string is a valid key; it'sdict["1.5"]
.Not to mention that different strings can represent the same number - e.g.
Those are 6 distinct keys because they're 6 distinct strings.
Agreed. In javascript for this kata, arbitrarily having to convert/parseInt any string that "could" evaluate to a number, into a number, in order to pass this test, would leave errors for keys defined as strings...that could be evaluated to a number.
Couldn't agree more.
I think the kata description should specify that the sort needs to be stable. This comes up in the Haskell random tests when some of the values are equal and if I use reverse instead of changing the comparison function.
The JS version also requires the sort to be stable.
This is a solid Python kata, but the Javascript version distracts from the point because the programmer has to hack around Javascript's conversion of number keys into string keys (as mentioned by OverZealous).
I am getting an error "str$ is not defined" when I am trying sample testcases in js
Yeah, there's some garbage left in there, I assume from the Python version.
Also, referring to "numbers as keys" in the JavaScript challenge really doesn't make sense, simply because JavaScript can't have numbers as keys (anywhere, even arrays, they are basically converted to strings and stored as a hash on the array object!).
Not much can be done about that last part, though, since it's part of the original kata.
Isn't
str$ not defined
a result of the preload-doesn't-work-on-example-test-cases bug? After all,str$
works fine in the regular test cases.A small workaround would be
var str$ = JSON.stringify;
at the start of the example test cases.As @bkaes wrote it
str$
is just an alias forJSON.stringify
. Example test cases were copy/pasted from final test cases but i've forgotten to copy/pastevar str$ = JSON.stringify
too (shame on me) !Users may add it at the start of their test cases, or replace
str$
byJSON.stringify
. As the translation is now approved, only the sensei (@cmgerber) may modify the kata.@ZozoFouchtra: Nah. You haven't forgot anything, your preload code is fine (you can see the preload code if you start a translation). It simply doesn't get preloaded on example test cases.
This bug has been in for about 2 months, so it happened after yout translation. There are several bug reports on this matter, but all apparently most of them just said "It doesn't work sometimes" or "it doesn't work in that specific kata". Since this bug happens almost everywhere nowadays, I added a new bug report. Maybe it isn't a defect, but intended, but I doubt that.
@bkaes That makes sense.
It threw me off, since
str$
is a very not-JavaScript-like name for a function, and the JavaScript testing library has a built-inTest.assertSimilar
method that works fine forArray
s (just notObject
s).For this specific case, I fixed the JS kata to use
assertSimilar
. I'll make sure that Jake is aware of the bug for example test cases (although I believe he is).JS-translation kumited ( 4 weeks ago )
One test in the "coding view" is done twice.
Typo in description (larges => largest).
Thanks, updated.
It could use a couple more tests as examples. In particular, something with less symmetric order to make it clear what is the desired output.
Thanks, just added another.
This comment has been hidden.
This comment has been hidden.
You should name the argument something other than "dict" since "dict" is a builtin.
Good point, I will update that.