Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Given a string, find the non-repeating characters and return in form of an array
function findNonRepeatingChars(string) {
const stringArray = string.split('')
const nonrecurring = []
const resultObj = {}
for(let char of stringArray) {
if(!resultObj[char]) {
resultObj[char] = 1;
} else {
resultObj[char] += 1;
}
}
for(let char of stringArray) {
if(resultObj[char] == 1){
nonrecurring.push(char)
}
}
return nonrecurring
}
findNonRepeatingChars('apple')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.