6 kyu
Another one down—the Survival of the Fittest!
74 of 772bkaes
Loading description...
Lists
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.
The code is ok, but in the last test still getting error!!! I will skip this kapa.
There is an issue at least in this test: ' remove_smallest(4, [-87, -47, 41, 84, -21, 29, -89, 13, -32, 52, 43, 92, -30, -7, 63, -80, -70, 59, 99, 25, -70, -62, 81, 97]) '
my script does remove: ' -89 , -87, -80, -70 ' without changing the order of the list, but still getting an error! , as the final list is : ' [-47, 41, 84, -21, 29, 13, -32, 52, 43, 92, -30, -7, 63, 59, 99, 25, -70, -62, 81, 97] '
This comment has been hidden.
This comment has been hidden.
By simply assigning the array to a new variable, you're only creating another reference to it, not a copy of it.
This comment has been hidden.
python new test framework is required. updated in this fork
Approved
Nice!
def remove_smallest(n, arr):
This should work perfectly but it just doesn't when it gives the randomized ns and arrays. I even tested this on pycharm and it worked perfectly with the examples which weren't working here. Also I know finding the smallest index of the smallest number is irrelevant but I didn't feel like changing the code after realising.
Not a kata issue! Tests do check whether input modification has been made and your code violates that!
This comment has been hidden.
The kata asks you to remove
n
smallest element inarr
, not to remove elements that are smaller thann
fromarr
Sample tests should not be random.
Hi, something is wrong with this or something I miss:
"didn't work for n = 121... Expected: '[246, 191, 81, 101, 498, 94, 319...]"
81, 94 are below than 121...
Read the instructions again, you have to return an array with
n
smallest numbers removed, not all numbers smaller thann
.Thanks, I missunderstand the instruccions.
It seems the test don't work properly, plus the normal situation where it should take a number of items smaller than the list size is not considerd.
Python
The test asks for n items to be removed and yet it expects a copy of the original list.
for _ in xrange(10): n = randint(0,25) --> If you put randint(0,0) works as expected arr = build_random_arr(n + randint(2,25)) copy = list(arr) remove_smallest(n,arr) test.assert_equals(arr,copy,"you've changed the input")
Am I missing something? Why does test
Expected: '[494, 491, 486]'
for this (link below) array? https://jsbin.com/bavagak/1/edit?js,consoleThe tests for Not Modify Arr in python are throwing me errors and I'm not sure why. I'm not modifying the input because I copied the arr to variable. Then remove the elements from the copied list stored in the variable. Additionally, instead of removing the elements the modified list returns a way longer list than the original arr in the input. I'm sure I'm missing something but...
It seems that something wrong in random tests:
JavaScript. n = 1; array.length = 5 array: [ 33, -23, 35, 11, 48 ] removed item by my function: [ -23 ]
✘ you've changed the input - Expected: [33,-23,35,11,48], instead got: [33,35,11,48] How could it expect the same array with n = 1???
did you see "you 've changed the input"?
I thought that it is the name of the test... Closing the issue.
Nice little kata here! Definitely challenged me.
Using entirely random data in the tests can lead to some unexpected results. Also, it makes it hard to diagnose the root cause of the failure. Tests should be deterministic in order to be repeatable and should also help the developer diagnose the error quickly.
Yes and make the values of n smaller so it's actually feasible to quickly compare the expected vs obtained result
Already raised as issue
This comment has been hidden.
It fails for the "don't modify the array" tests too. Because, well, you are modifying the array. You should make a copy, modify it and return that.
Some random tests doesn't seem to be accurate.. If I didn't missunderstood the kata asks for an empty array response if n > arr.size but the tests expect an array with lots of numbers.
Description quote: "If n is greater than the length of the array/list, return an empty list/array"
One example: n => 105 ; arr.size => 734
Which language? Also note that the
n
in your example is a lot smaller than the actual array size.Totaly my bad @bkaes .. I don't know honestly what I was thinking when typed this .. closing my issue now .. so sorry for wasting your time !!
I do think this is a good kata.
Ruby: Example in description is not visible. (It is for other languages)
Thanks for pointing this out. Ruby specific examples added to the description.
Great
Ruby:
Tests take too long to run.
There are no static tests that the method does what is asked.
There are too many redundant tests.
Random test arrays are too big to be able to diagnose what caused the failure.
I tried the tests several times and they always finish in 1-1.5s. I don't really think that's too long.
Good point. Static Tests added.
I'm not entirely sure what you mean by that. I modified the tests so n is not greater than the length of array as often as it used to be. So the answer won't be
[]
that often. Is there any other redundancy I'm missing?1.5 seconds is ok for a full test but is too slow when you are trying to develop a solution.
These run in < 250ms (often less than 100)
Maybe split it up with 'Describe's so that it runs in sections.
Redundant tests: All the ones that are runing 10.times testing the same thing.
They're basically translations from the following properties (in Haskell):
The
property
will generate 100 tests with random arguments. The Ruby translator basically did the same with10.times
. Note that the tests have different semantics.That doesn't really provide more info than splitting with
it
.Oh. You've never solved a kata in Clojure or Haskell, right? The tests there take at least 1 second :D.
Also, if you want to use less random tests, you can easily reduce the
10
to something lesser.All in all, I think that—beside the previously missing static tests—the "issues" are more or less personal opinions. I trust the instincts of the Ruby translator and leave them as is.
By the way, the Codex' Ruby section needs some help. In case you're interested.
Oops. I must have missed your reply.
As bkaes said, the 10 times repetition was just to emulate the property usage in haskell.
And as for test-time while developing the solution, on top of what bkaes said, one should use the example tests while developing the solution. They take less than 250 ms.
Here's a challenge for you then, write code to solve the kata which fails 1 and passes the other 9 of each of these tests.
I agree with that.
Redundancy removed. Property checks now only check the property for one random array.
Thanks CrazyMerlyn.
Nice one
Python translation kumited.