implements rotate method for array