Skip to content

Instantly share code, notes, and snippets.

@P1xt
Created August 5, 2014 09:08
Show Gist options
  • Save P1xt/97db232fad48d8beec8b to your computer and use it in GitHub Desktop.
Save P1xt/97db232fad48d8beec8b to your computer and use it in GitHub Desktop.
Set Intersection
var fs = require("fs");
fs.readFileSync(process.argv[2]).toString().split('\n').forEach(function (line) {
if (line != "") {
console.log(processLine(line));
}
});
function processLine(line) {
var lists = line.split(";");
var list1 = lists[0].split(",");
for(var i=0; i<list1.length; i++) { list1[i] = parseInt(list1[i]); }
var list2 = lists[1].split(",");
for(var i=0; i<list2.length; i++) { list2[i] = parseInt(list2[i]); }
var listReturn = [];
for (var i = 0; i < list1.length; i++) {
if (list2.indexOf(list1[i]) != -1) {
listReturn.push(list1[i]);
}
}
return listReturn.join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment