Skip to content

Instantly share code, notes, and snippets.

@demian85
Created August 9, 2011 20:16
Show Gist options
  • Save demian85/1135081 to your computer and use it in GitHub Desktop.
Save demian85/1135081 to your computer and use it in GitHub Desktop.
GDD2011 test #3
var util = require('util'),
fs = require('fs');
// textos...
var txta = fs.readFileSync('a.txt', 'utf8');
var txtb = fs.readFileSync('b.txt', 'utf8');
var words = txtb.trim().split(/\s+/);
var uniq = [];
words.forEach(function(w) {
if (uniq.indexOf(w) == -1) uniq.push(w);
});
uniq.sort(function(a, b) {
var chars = 'bhtsxnkpfjgrcmvlwzdq'.split('');
var achars = a.split('');
var bchars = b.split('');
var word1 = 0;
for (var i = 0, len = Math.min(a.length, a.length); i < len; i++) {
if (chars.indexOf(achars[i]) < chars.indexOf(bchars[i])) word1--;
else if (chars.indexOf(achars[i]) > chars.indexOf(bchars[i])) word1++;
if (word1 != 0) break;
}
if (word1 < 0) return -1;
else if (word1 > 0) return 1;
else return 0;
});
console.log(uniq.join(' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment