6 kyu
uniq (UNIX style)
1,406 of 2,621x-way
Loading description...
Arrays
Filtering
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.
Scala translation
One of the earlier Kata's. Nowadays this thing would have been rated an 8kyu. ;-)
Haskell translation
Prolog translation
Approved
This comment has been hidden.
OP solved it, closing
Expected: equal to [ ]
Actual: [ ]
This is in C++. I passed the random tests but failed this particular fixed test. I see others having the same issue here. Any help?
Tests are OK, and all people who reported such problem finally found the error in their solution, so your solution probably has similar error too.
I just solved the kata in C++ and encountered no problems. I checked fixed test cases and they seem to be OK.
This paragraph and this paragraph of FAQ can be helpful.
You're right. I did find an issue in my program where it erased the last "" element when compared with an empty value beyond what my vector was initialized with (Not too sure how to refer to it). Thank you for the reply!
Cool kata and it's also a problem that you have to solve very often :)
This comment has been hidden.
Not an issue. Your solution is wrong.
I thought it was, cause there were two other comments pointing at the same problem. Can you tell me what causes this to happen / what I need to change in my code? I really have no idea whatsoever. Would be nice of you :) (not a solution, but explaining why this error is caused so I can fix it myself, atm I don't have any clue where to look)
Have you tried printing the input?
C++: when I submit my solution, I get one fixed test case wrong, and the error message looks like this: Expected: equal to [ ] Actual: [ ]
Is there a problem with the grader, or is it my code's problem?
C++ TEST: Expected: equal to [ ] Actual: [ ]
WTF?
Can you please give me the input for which this happens? Becuase I've tried re-creating the tests, but it didn't occurred to me.
Sorri, I don't speak English very well. Already passed the tests and added to solutions. Thank you
I'm pretty sure you've slipped through the random tests.
I'm not sure. I'm having the same problem (see my comment above), and the test my solution is failing on is a fixed test. The test seems to be a vector with an empty string in it. EDIT: I just solved this kata in Python with the same exact approach and it worked. I see that many others are also having trouble with the C++ version of this kata, and not with any other languages. Maybe a slight problem with the C++ translation?
C++ translation. Please, review and approve (the author is inactive).
C++ TEST: Expected: equal to [ ] Actual: [ ]
WTF?
The user is allowed to mutate the input. There should be a test against that
Which language?
Python: https://www.codewars.com/kata/reviews/5eb876bb0f61730001e2edf4/groups/5eb9273aa597b900014f7ea7
The description says nothing about whether the user should or should not modify the input. Why should it become forbidden 7 years after the kata was published?
This a bit too ez for a 5 kyu these days
sure... for a 6...
whoops, didnt see a 6(thought it was a 5), but it should be a 7.
EDIT: Ik it published in 2013, so yea.
If it got re-ranked to 7 Kyu, you'll probably say "it should be 8" xD
Go translation kumited. Please review and approve. Regards, suic
Can someone approve the translation? Thanks, suic
This comment has been hidden.
Not an issue. Have you read the requirements carefully? ;-)
[''] should equal []? And [] should equal ['']? Realy? Why?
Tests:
Example Tests Test Passed Test Passed [''] should equal [] Test Passed Test Passed [] should equal [''] Test Passed Completed in 0.06ms
This means you are returning [''] for a test expects []. Also you are returning [] for a test expects [''].
Python translation
JS :
Fixed the first two
Fixed.
The test descriptions absolutely suck - how are we supposed to know what is expected when the test output simply reads "The value is not what is expected"
Worst Kata I've taken
Which test are you failing? If you're still having problems, just post your code using Markdown formatting and I'll help ya.
This comment has been hidden.
You should notice about "undefine" condition in kata description.
I get the error: "Test Failed: Value is not what was expected" on the 17th Tests. Which value is expected? What was the test fixture?
My result is correctly returning array a,b,c,a,b,c, but i get an error each time stating something like: input array value of undefined should return output array of undefined ideas?
This message alerts you to an error in a test case seperate from the a,b,c,a,b,c-one. You shoud improve your solution to handle [undefined] as input.
This comment has been hidden.
Incorrectly reporting error if you do not return a value - it will return an error saying it can't get the length of undefined, which originally lead be to believe that there was an error in my code till I realized i forgot to return..
Most of the solutions will fail with
NaN
's:uniq([NaN, NaN])
should return[NaN]
.Probably, there should be test for that case.
This comment has been hidden.
This comment has been hidden.
The instructions for the problem might be made a bit more clear with a small change...
Implement the uniq() function which behaves like the uniq command in UNIX. It takes as input an array and returns an array in which all duplicate elements immediately following each other have been reduced to one instance.
..because in the array ['a',b','a'] the second a "follows" the first and is a duplicate, but the solution only wants to collapse adjacent dups.
Unless I'm mistaken, that fits with the UNIX uniq command: see http://www.ss64.com/bash/uniq.html
But it would probably be clearer to those who don't live on UNIX or UNIX like machines ... ;)
... with all consecutive duplicate elements removed ... ?
Thanks, I've updated the test cases to cover undefined values in the input array.
My solution breaks if you give [undefined,'a', 'a', 'b', 'a','a'] as the array to the solution function. You probably want my solution to fail.
The correct way to do it with shorthand notation is the way x-ray did it.
Ah, I was thinking along the lines of http://underscorejs.org/#uniq or http://api.jquery.com/jQuery.unique/ - I didn't notice UNIX in the description. Oops! =)
No, uniq(['a','a','b','b','c','a','b','c','c']) should return ['a','b','c','a','b','c'].
uniq only reduces consecutive duplicate entries (see also: https://en.wikipedia.org/wiki/Uniq).
No problem. Don't forget to change your output array to ['a','b',c'] or good code will fail. uniq(['a','a','b','b','c','a','b','c','c']) should return ['a','b',c'] for output.
Thanks for pointing out this flaw in the test case. I've added a length verification and some more tests to test various aspects of the uniq() behaviour.
CHANGE: var output = ['a','b','c'];
AND ADD: Test.expect(x.length == output.length); OR CHANGE: for (var i=0;i<output.length; i++) {
Something along those lines.