Right Triangles Leetcode Javascript Question