u/greaseBTC - 5 Archived Voat Posts in v/programming
u/greaseBTC
  • home
  • search

u/greaseBTC

1 post · 4 comments · 5 total

Active in: v/programming (5)

  • ‹‹‹
  • ‹‹
  • ‹
  • 1
  • ›
  • ››
  • ›››
Comment on: We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.

I think you won at code golf.

1 28 Apr 2016 18:38 u/greaseBTC in v/programming
Comment 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]

0 28 Apr 2016 18:38 u/greaseBTC in v/programming
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.

0 28 Apr 2016 18:30 u/greaseBTC in v/programming
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);
});
2 15 Apr 2016 09:45 u/greaseBTC in v/programming
We need more programming challenges. We should start off small: First non-repeating character of a string. Any language you like.
34 67 comments 15 Apr 2016 09:42 u/greaseBTC (self.programming) in v/programming
  • ‹‹‹
  • ‹‹
  • ‹
  • 1
  • ›
  • ››
  • ›››

archive has 9,592 posts and 65,719 comments. source code.