Minimum Array End Leetcode Javascript Solution