Leetcode Rotated And Sorted Array In Js For Loop