JSFiddle - React, Tailwind, and code Playground
by danbeam
JavaScript
function dedupe(str) {
str = Array.prototype.slice.call(str);
str.sort();
for (var i = 0; i < str.length - 1; ) {
//console.log(i, str[i], str[i + 1], str);
if (str[i] == str[i + 1])
str.splice(i, 1);
else
++i;
}
return str.join('');
}
function assertDifferent(str) {
var deduped = dedupe(str);
console.log(str, deduped);
if (str && str == deduped)
throw 'fail';
}
assertDifferent('aaa');
assertDifferent('abbbba');
assertDifferent('cccaccc');
assertDifferent('');