Skip to content

Instantly share code, notes, and snippets.

@tamunoibi
Created April 9, 2018 21:27
Show Gist options
  • Save tamunoibi/416ed7f0502575b2d36fa71c14e734f0 to your computer and use it in GitHub Desktop.
Save tamunoibi/416ed7f0502575b2d36fa71c14e734f0 to your computer and use it in GitHub Desktop.
function removeDuplicates(str) {
//remove all non alphabets
var expression = /[^a-zA-Z]/g;
var unique = [];
var repeated = [];
var obj = {
uniques: [unique],
duplicates: [],
};
str = str.replace(expression, "").split();
//search for repeating letters
for (var i = 0; i < str.length; i++) {
for (var j = 0; j < str[i].length; j++) {
if (unique.indexOf(str[i][j]) === -1) {
unique.push(str[i][j]);
} else {
repeated.push(str[i][j]);
}
}
}
return obj;
}
removeDuplicates("xxyxzlp346");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment