Rotate the Array by One 🔄

Published by Werdna in

Given an array, rotate the values clockwise by one (the last value is sent to the first position).

Check the examples for a better understanding.

Examples

rotateByOne([1, 2, 3, 4, 5]) âžž [5, 1, 2, 3, 4]

rotateByOne([6, 5, 8, 9, 7]) âžž [7, 6, 5, 8, 9]

rotateByOne([20, 15, 26, 8, 4]) âžž [4, 20, 15, 26, 8]

Notes

N/A

Watch a quick demo on how Edabit works.