Some tips for merging same values in an array