Removing panic from rotate_left and rotate_right

I was working on this Leetcode problem (https://leetcode.com/problems/rotate-array) and found that rotate_right and rotate_left panicked when the value to rotate by exceeded the length of the vector being rotated.

I started playing with it and discovered the same thing other members have posted about previously and have come to the same conclusions: Remove panic from rotate_left and rotate_right?

I agree with that the panic is unnecessary. I also agree that using rem_euclid() to calculate the shifting amount for values greater than len() makes sense as a solution. I think the language should adopt these changes either as wrap_rotate_right() and wrap_rotate_left() and/or simply as rotate() (which would be my preference).

1 Like

Open an ACP

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.