var str = "aabb" var arr = str.split(""); arr.sort(function(a,b) {return a.charCodeAt()-b.charCodeAt();}) console.log(arr) const newArr = [...new Set(arr)] console.log(newArr) console.log(arr.length - newArr.length)