function duplicates(arr) { var obj = {}; var newArr = []; for (var i in arr){ if(obj[arr[i]]){ obj[arr[i]]++; } else{ obj[arr[i]]=1; } } Object.keys(obj).forEach(function(key){ if(obj[key]==1){ newArr.push(key); } }); console.log(newArr); var str = newArr.join(''); console.log(str); var newarr2 = []; newarr2 = str.split(''); console.log(newarr2); } duplicates([1,2,3,3,6,6,5]);
添加回答
举报
0/150
提交
取消