function Unique(A) { var n = A.length, k = 0, B = []; for (var i = 0; i < n; i++) { var j = 0; while (j < k && B[j] !== A[i]) j++; if (j == k) B[k++] = A[i]; } return B; } alert( Unique([1,7,2,1,5,8,2,3,4,5,9,5,7]) );