Javascript Remove Duplicate Objects From Array Using Function