Find Distinct Elements In Array Javascript Iteration