var res = []; function Init() { res = []; } //Insert one char from stringstream function Insert(ch) { if( res[ch] ){ res[ch]++; }else{ res[ch] = 1; } } //return the first appearence once char in current stringstream function FirstAppearingOnce() { for( var ch in res ){ if( res.hasOwnProperty(ch) ){ if( res[ch] == 1 ){ return ch; } } } return '#'; }