6 kyu

Another one down—the Survival of the Fittest!

74 of 772bkaes
Description
Loading description...
Lists
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • AlbertCarri Avatar

    The code is ok, but in the last test still getting error!!! I will skip this kapa.

  • MihaiS7 Avatar

    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] '

  • sfcsarah Avatar

    This comment has been hidden.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • Uranium7100 Avatar

    def remove_smallest(n, arr):

    if n > len(arr):
        return []
    
    if n <= 0:
        return arr
    
    while n > 0:
        x = (arr.index(min(arr)))
        
        arr.remove(arr[x])
        
        n = n - 1
    return 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.

  • Omerap12 Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    Sample tests should not be random.

  • Maxitenia Avatar

    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...

  • Homeralf Avatar

    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")

  • YozhEzhi Avatar

    Am I missing something? Why does test Expected: '[494, 491, 486]' for this (link below) array? https://jsbin.com/bavagak/1/edit?js,console

  • lclaytont Avatar

    The 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...

  • AlexDubok Avatar

    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???

  • HerrWert Avatar

    Nice little kata here! Definitely challenged me.

  • Carnubak Avatar

    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.

  • matthewbryancurtis Avatar

    This comment has been hidden.

  • GonzoGhanem Avatar

    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

  • Insti Avatar

    I do think this is a good kata.

  • Insti Avatar

    Ruby: Example in description is not visible. (It is for other languages)

  • Insti Avatar

    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.

  • NaMe613 Avatar

    Nice one

    Python translation kumited.