I want to remove all the duplicate numbers and the function will return a unique number that has no duplicate number. Suppose I have this array [1,2,2,3,3,4] I want to return [1,4] because 1,4 doesn't have duplicate numbers.
This is my code and the problem is I am getting duplicate numbers too. The Input of this function is [6, 1, 2, 3, 1, 2, 2, 3] and the output should be [6]
Can anyone help me with how can I solve my problem?
function deleteProducts(ids, m) {
// Write your code here
var uniqueArray = [];
// Loop through array values
for (i = 0; i < ids.length; i++) {
if (uniqueArray.indexOf(ids[i]) === -1) {
uniqueArray.push(ids[i]);
}
}
return uniqueArray;
}
deleteProducts([6, 1, 2, 3, 1, 2, 2, 3]) // output [6, 1, 2, 3]