Leetcode First Repeating Element In Array Javascript Reduce