How to deduplicate an array with the complexity of O (n)? (js)

problem description:

 `O(n)` 
[1, "asides," 1", 2,"2", "baked," b", null, null, "null"]

1 and"1" are not duplicates but, undefined, null should be retained. Do not use the syntax of ES6.

Aug.11,2021

var arr = [1, 'a', '1', 2, '2', 'b', 'b'];
let resultarr = [...new Set(arr)]; 
console.log(resultarr);//[1, "a", "1", 2, "2", "b"]

if the object is not duplicated, you can use the following

var arr = [1, 'a', '1', 2, '2', 'b', 'b', null, null, , ,'null'];
var obj = {};
var result = [];

for (var i = 0; i < arr.length; iPP) {
  var key = typeof arr[i]+arr[i];
   if(!obj[key]){
     obj[key] = true;
     result.push(arr[i])
   }
}
console.log(result);

//
for (var i = 0; i < arr.length; iPP) {
  var key = typeof arr[i]+arr[i];
   if(!obj.hasOwnProperty(key)){
     obj[key] = arr[i];
   }
}

console.log(Object.values(obj));//es5 for in

can be put in a bucket


es6

var arr = [1, 'a', '1', 2, '2', 'b', 'b']
arr.sort();
for(var i = 0 ;i <arr.length;iPP){
    for(var j = i+1;j<arr.length;jPP){
        arr[i]===arr[j] ? arr.splice(i,1) :''
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5f2c6-671ad.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5f2c6-671ad.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?