Leetcode First Repeating Element In Array Javascript Length Function