This will remove dups then transform the object into an array to later joining it.
function removeDupes(str) {
let newStr = new Set(str) // O(n)
newStr = Array.from(newStr) // O(n)
return newStr.join('') // O(n)
}
console.log(
removeDupes('abcd'), // abcd
removeDupes('aabbccdd'), // abcd
removeDupes('abababcdcdcd'), // abcd
)
// Time: O(3n) => O(n)
// Space: O(n)