6 kyu

The range() function

2,053 of 2,140user5363957
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • ameenj Avatar

    The case where there could be 3 arguments, but step is 0 was the tricky part for me.

  • viaco12 Avatar

    Having finished the kata, I don't think the edge case of step === 0 is explained properly. There's a single example but no explanation of where the solution comes from. You basically have to guess as to what the kata wants. I think the description should be edited to include some kind of instructions for when step is 0.

  • NadCAtarun Avatar

    Who in their right mind would decide to make the first argument optional but not the next one?

    If start is optional and not stop, then the proper signature should be range(stop, start = 0, step = 1).

    Also the behavior for step = 0 or start > stop make zero sense to me.

  • jadoremath Avatar

    if step equals zero, how can "if(step == 0") not work??? it's just annoying

  • Schanya Avatar

    Why should the function range(1,5,0) return [1,1,1,1]? (four elements).

    But the function range(0,2,0) should return [0,0]?(two elements)

    Of course, if you trust the tests :)

    Please explain if I'm wrong.

  • fishenal Avatar

    I really comfuse with param stop. As description it mean the interger in array's max value. but in step 0 case like range([1, 4, 0]) return [1, 1, 1] if seems like means the max index of array. For the first understanding logic, step 0 will never stop, becuz the value of the interger won't touch the max. If understand 'stop' to max index, case range([1, 11, 1]) return [1, 2, 3, 4 ..., 10], will also wrong. Is there some misunderstanding for me? or this one has issue?

  • NunoOliveira Avatar
  • laurelis24 Avatar

    Nice kyu. Once you understand how step 0 should be done its not that hard... :)

  • MarcinMoskala Avatar

    It seams that random tests are incorrect for Go.

    I got for instance:

    With start = 7, end = 21, step = 10 Expected <[]int | len:2, cap:2>: [7, 17] to equal <[]int | len:1, cap:1>: [7]

    The actual solution is correct, not the expected one.

  • akar-0 Avatar
  • donaldsebleung Avatar

    Description did not mention at any point what should be done if no arguments at all are passed to range(), but this is tested in the random tests.

  • DavidFromNorth Avatar

    the worst description I've ever seen smfh... this one must be removed

  • FArekkusu Avatar

    No random tests.

  • goofballLogic Avatar

    Going to not complete this on purpose :) Bad kata i think.

  • Arheus Avatar

    How this kata got out of beta is beyond me.

    The description clearly states: Returns a list of integers from start to stop, incremented (or decremented) by step, exclusive.

    In that case, (1,4,0) should return an infinite list of 1's, since by incrementing 1 by 0 you will never reach 4.

    Next: out of the three parameters, two are optional. The description never explains what happens when the function receives two parameters. Is it start, stop ? Or is it stop, step ? One shouldn't do detective work on the test cases to find out the answer to that one.

    If I could down vote this, I would.

  • parabola949 Avatar

    Really shouldn't have optional arguments first. Granted, in this particular case, we could work around it. Still. Let's think about this. range(10,1) could mean end 10 step 1([0,1,2,3,4,5,6,7,8,9]), or start 10 end 1 ([])

    What if it were something else? For example createContact([someNumber],deskPhoneNumber,[someOtherNumber]); Note: number only, no dashes. I pass two parameters. Tell me which numbers they are?

    Also agreeing, (1,4,0) == [1,1,1]??

  • muchzill4 Avatar

    range(1, 4, 0) => [1,1,1]

    Wait. What?

    Imho it's "Process was terminated. It took longer than 6000ms to complete".

  • paool Avatar

    This comment has been hidden.

  • MarcoV Avatar

    Like the others i disagree with the outcome of the 0 step test. If something does not incriment each step then it would create an infinite loop. If you meant that the step should incriment 1 as a default value if nothign was set or if it was set to 0 that was not stated, but even if that was the case in my head it still should not return 1,1,1 but 1,2,3. Could you explain more why it should return this?

    I could add in an extra part to my code so it would read the step as 0 but still incriment as 1 by default and print out the 1,1,1 but like I said in my head thats not how it should work.

  • Alban Avatar

    A little dissapointed with this Kata, overall it has a very good aim. However it is contradictory

    range(10, 0); // /!\ note that the end is before the start => [] range(0, -10, -1); => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] Shouldnt this also return [] considering 0 comes before -10?

  • wthit56 Avatar

    I think the description needs some work. /!\ note that the step is 0 and /!\ note that the end is before the start don't help the coder understand what behaviour is expected in these situations. Also, I'm not sure the result from a 0-step call makes much sense. I guess it's some edge-case to mimic some implementation, but this should be explicitly explained.

  • jacobb Avatar

    Need to reread the description, but I would suspect some infinite loops from my current solution. Would be good to specify which language's range function you're specifying.

  • TiTi Avatar

    Really like dpellier solution!

  • BattleRattle Avatar

    why is this the expected behavior?

    range(1, 4, 0); // /!\ note that the step is 0
    => [1, 1, 1]
    

    If you have no increment (step = 0), how do you define the amount of items? Sounds illogical to me.

  • user5363957 Avatar

    Indeed, you're right, thanks for pointing out this case. I've updated the description and the test cases as well. Thx.

  • frenetic_be Avatar

    Could you please mention in the description what is expected if step = 0. i'll mark it ready then. Nice kata anyway.

  • xDranik Avatar

    Can you mention in the description that you should return the array after you've either:

    1. Passed the end value
    2. Have Math.abs(end-start) values in your array