Created
April 9, 2018 21:27
-
-
Save tamunoibi/416ed7f0502575b2d36fa71c14e734f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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