复杂类型去重
var arr = [1, 2, 3, 1, 2, 3, { a: 1 }, { a: 1 }, { a: { b: 3 } }, { a: { b: 3 } }, [1, 2, 3], [1, 2, 3]]
function removeDuplicate(arr) {
let lens = arr.length
let tempArr = arr.map((item) => {
return JSON.stringify(item)
})
let newObj = tempArr.filter((item, index, arr) => {
return tempArr.indexOf(item) === index
})
let newArr = newObj.map((item) => {
return JSON.parse(item)
})
return newArr
}
removeDuplicate(arr)
字符重复最多
var str = 'xuzzyxyyz'
var twoSum = function(str) {
var lens = str.length
var obj = {}
for(var i=0;i<lens;i++){
var x = str.charAt(i)
if(obj[x]){
obj[x]++
}else{
obj[x] = 1
}
}
var max = 0
for(var key in obj){
if(obj[key] > max){
max = obj[key]
}
}
for(var key in obj){
if (obj[key] == max) {
var res = {key,max}
console.log(res)
}
}
};
twoSum(str)