Question: Write an array deduplication function. (use as many methods as possible)
//Such as input array [1,"a",{b:2},{c:3},{b:2},{b:"2"},"1","a"], return [1 ,"a",{b:2},{c:3},"1"]
function unique(arr) { var temp=[]; // store new array var keys = []; // store object key set for ( var i=0; i<arr.length; i++ ) { var a = arr[ i]; if ( typeof a !== "object" ) { var idx = temp. indexOf(a) if (idx>-1 ){ continue ; }else { temp.push(a); } } else { for ( var k in a) { var idx1 = keys.indexOf(k); if (idx1===-1) { // if the object doesn't exist in keys yet keys.push(k); // store key temp.push(a); // value store new array } } } } return temp; }