Skip to content

Instantly share code, notes, and snippets.

@sergi
Created May 7, 2013 10:31
Show Gist options
  • Save sergi/5531711 to your computer and use it in GitHub Desktop.
Save sergi/5531711 to your computer and use it in GitHub Desktop.
function firstUnrepeated(str) {
var blacklist = [];
var once = {};
str.split("").forEach(function(e, pos) {
if (blacklist.indexOf(e) === -1) {
once[e] = pos;
blacklist.push(e);
}
else { delete once[e]; }
});
return Object.keys(o).reduce(function(prev, cur) {
if (!o[prev] || o[cur][1] < o[prev][1])
return cur;
return prev;
}, null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment