Write a function to find the first non-repeated character in a string
After playing a lot with jsperf and having to admit that the regex solution is actually faster, which annoys me.


Your first approach is far superior than your second approach (O(2n) -> O(n^2)) as per Venu
you should cache string.length, looking up the value of a property slows things down

for(var i = 0, length = string.length; i &lt; length; i++){

You can assign More than one and One time with a ternary, also you should cache string[i] and not look it up 3 times:

charCount[c] = charCount[c] ? 'More Than One' : 'One Time';

You do not need var j, just use i again
You used string[i] everywhere else, your return statement should be return string[i];
repeater is a terrible name if you are planning to return a non-repeater ;)
from a design perspective, I would return '' instead of 'Everything is repeated', because really, '' aka nothing is repeating


On the whole I think your code is fine, I am not sure ( besides the magical regex ) how it could be done much faster. You need something to track the character count and I am not sure how you can avoid the second loop.

Update: books.google.com/books?isbn=1118169387 &lt;- This pretty much agrees that your first approach is as fast as it gets ( except for the mind boggling regex ;)