7 kyu
Sort arrays - 1
3,570 of 15,870ineiti
Loading description...
Sorting
Arrays
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.
Java:
Strongly suggest to revamp the test suite to just use
String[]
which uses natural ordering as the sorting criteria (lexicographically ordering) , same as C# , TS and other strongly typed languagesit is 8 kyu
Array sorting: the ultimate challenge! 🥷
TypeScript Translation for review / approval
Approved!
Java! Thanks!)))
R translation (author inactive)
On WHAT criterium do you need to sort the list?
Added to description
Description should probably mention that array must be sorted in lexicographical order.
Added to description
C++ translation
This comment has been hidden.
Ranks can't be changed
Duh, that's a shame. Why tho?
Yes, it most definitely should!
ok, this was kind of asking myself "in what way can those weird elements sorted?" Answer: Yes!
Crystal, Julia && Python (author inactive)
Very cool Kata!! I used java. Tests are correct, you need to think!
No sample tests and random tests, using
Test.expect
in JS and Ruby. It is not specified that the input is an array of strings which is important in JS.Actually, it's not. You can optimise if you know input is an array of strings, but you don't have to do that.
Added(updated JS to Node 12. as well)
This comment has been hidden.
It is a generic type, which means that you can give any type you want to replace the T generic type.
No sample tests, serious lack of tests on Javascript and CoffeeScript (possible in other languages too).
Added(updated JS to Node 12. as well)
Java version corrected:
Java version is completely wrong.
Really disappointing.
To anyone trying the java version: you'll have to declare SEVERAL methods.
I guess it makes it a little fun, I thought of this more as a 6kyu
except that you used the corrected version. It was way worse when I posted that issue.
Have anyone resolved this one in java? I think it may be impossible as it need to work on primitives and objects (returning type Object or usung generics does not work).
Name of input array makes no sense. Please change to numbers. I was confused and trying figure out how my solution not working with string length.
In Ruby, I'd score this 8kyu instead of 7
Same for python
The Java version has problems with its tests. It errors back "Cannot convert long to int" even though the method is to return an int[]. I solved this in JS just so I could downvote it.
It seems that the idea here is that a solution should be able to sort any array, i.e. object arrays (
Object[]
,String[]
,Integer[]
and so on),int[]
,long[]
,float[]
,double[]
and so on.For me, it just gives a bunch of errors. Solved it in JS to downvote it too lol
corrected
The Java version has problems with its tests. It errors back "Cannot convert long to int" even though the method is to return an int[]. I solved this in JS just so I could downvote it.
In this case, if there is a real problem, create this comment as an issue!
corrected
This comment has been hidden.
C#-Translation kumited!
https://www.codewars.com/kumite/57c1ec1f255724fa8e00004c
Please check and approve it! :-)
Could anyone tell me what's wrong with my solution, cause i can't find any mistake with it.
the java version has been corrected.
The method parameter name is
names
which has no meaning whatsoever.Should this really br approved?
This comment has been hidden.
This kata is just plain awful...
Stuck on this one - what names are we supposed to sort? Names with accents? Uppercase, lowercase? :/ There should be an example usage so that I know why sorted ['c', 'a', 'b'] doesn't equal to ['a', 'b', 'c']. (sortme(['c', 'a', 'b']) == ['a', 'b', 'c'] does print true for me)
Apparently there is more than one kata asking to do this.
This comment has been hidden.
It depends on what you call "sorting". Yes,
(which is really strange, by the way). This is one reason I use time zero-padded numbers for a long time already:
Which is correct. But thanks for the reminder ;) In the Kata I only test for alphabetic sorting, so this is not an issue.
Will be broken with string including numbers, like ["Flight93", "Flight 123"], or with non-ASCII characters. That's why localeCompare() should be required.
I think this thread highlights the need for more tests , or restrictions to the input advertised in the kata description.
This one is a little broken... it didn't say to sort the existing array.. it said to "output a sorted array"... so sorting the existing one should be a failure, IMO.
I don't think so. Sorting the existing array and returning that fulfills the requirement "output a sorted array". There is no requirement given, that says, that the original array must not be changed.
Why would any developer make a function to sort an existing array when that function already exists on the array? That's incredibly silly. So yes, to the letter of the "requirement", it works... logically, it makes zero sense to have such a function.
I saw one comment where somebody discovered the "sort"-function of JavaScript - at least for this person I think the Kata fulfilled its purpose!
With regard to changing the input-array, there was some discussion about whether this is good practice or not. There has been no conclusion, as far as I remember.
immutability is almost invariably a best practice. Consider a system where the array that is passed to this function was already sorted for a different purpose.
@blesh: Many of these katas don't make any sense. These are just exercises to improve your skills, learn language features you didn't know before or try out different ways to solve a problem.
Exactly. In my case I knew the sort function of array, but thought it would be more useful to me to try and write the good old bubble sort, which I haven't used for years. Then I realized I forgot about the many sorting techniques I've learnt in college. I guess this is the purpose of katas; to improve your skills and to get the rust off of you.
Seems more like the Karate term 'Kihon' would fit for these types of challenges.
What does 'kihon' mean? 'walking'?
That was interesting :)
This comment has been hidden.
This is so easy that it seems unworthy of a kata, no?
It was thought to be a series of katas, starting very easy and getting a bit more complicated in the third part...
This comment has been hidden.
Perhaps unhonorable but pretty instructional in other languages like Java! http://www.codewars.com/kata/sort-arrays-1/forks/java ( not sure if the correct link should be http://www.codewars.com/kumite/56ce5b40aa4ac74e65001e16?sel=56ce5b40aa4ac74e65001e16 ) :P