6 kyu

Every nth array element. (Advanced)

Description
Loading description...
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar
    • More fixed tests for negative start_index && interval should be added

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • Insti Avatar

    The test failure messages should show the inputs that failed.

  • ttapu Avatar

    Something is wrong in test cases in negative interval section (ruby). eg: [0, 1, 2, 3, 4].every(-1, 0) Expected: [0], instead got: [0, 4, 3, 2, 1]. Can not pass it with good solution.

    • Insti Avatar

      This is similar to the example case:

      [0,1,2,3,4].every(-2) # [0]

      The answer you are getting is what happens if you let the array index become negative. You should ensure that you stop when you get to zero, and don't go negative.

      This does not appear to currently be explicitly documented though. I will clarify the description.

    • ttapu Avatar

      ah ok, I see. Thanks

      Issue marked resolved by ttapu 5 years ago
    • Insti Avatar

      I've updated the description, hopefuly that is helpful. I'm not sure about the wording, suggestions for improvement are encouraged.

      But no wrapping

      When counting down from a positive index, stop when you are below zero. (This is different from Ruby's array indexing)

      Example:

      [0,1,2,3,4].every(-2,2)   # [2, 0]
      [0,1,2,3,4].every(-2,3)   # [3, 1]
      
  • Unnamed Avatar

    The element at start_index not being expected in the result when interval is negative looks strange. If that's what you intended to do then at least rename the argument.

  • ZozoFouchtra Avatar

    Hopefully the test cases will make it clear what should happen in these situations.

    Sorry, I think test cases are not clear enough and more explanation/examples are needed.