Comment on: We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.
1 28 Apr 2016 18:38 u/greaseBTC in v/programmingComment on: We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.
It's that or two spaces at the end of every line.
ctrl-h \n \n[4 spaces]
Comment on: We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.
Couldn't you stop at the first occurence of lastIndexOf === indexOf
var result
array.some(function(letter) {
if(word.lastIndexOf(letter) === word.indexOf(letter) {
return result=letter;
}
}
return result;
I suppose that wouldn't match your ES6 exactly.
Comment on: We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.
#!/usr/bin/env node
var readline = require('linebyline');
var lo = require('lodash');
function readFirstNonRepeatingOfStream(input,cb) {
readline(input).on('line',function(line) {
var counts = lo.countBy(line);
Object.keys(counts).some(function(char) {
if(counts[char] === 1) {
cb(char);
return true; //Breaks out of the loop.
}
});
});
}
readFirstNonRepeatingOfStream(process.stdin,function(char) {
console.log(char);
});
I think you won at code golf.