refact code of remove dup from array