Skip to content

Instantly share code, notes, and snippets.

@tin80122
Created August 19, 2019 06:52
Show Gist options
  • Save tin80122/19707f325f6fb0c8491b99bbe2d8b339 to your computer and use it in GitHub Desktop.
Save tin80122/19707f325f6fb0c8491b99bbe2d8b339 to your computer and use it in GitHub Desktop.
var firstUniqChar = function(s) {
var ary = s.split('');
var counter = {};
for(var i = 0; i< ary.length; i++){
if(!(ary[i] in counter)){
counter[ary[i]] = 1;
}else{
counter[ary[i]] += 1;
}
}
console.log(counter);
Object.keys(counter).map(function(key,index){
if(counter[key] === 1){
return key;
}else{
return -1;
}
})
for(var j = 0 ; j < counter.lenght ; j++){
console.log(counter[j]);
}
};
var a = firstUniqChar("leetcode");
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment