Count Distinct Elements In Array Javascript Push To Beginning