Created
August 5, 2014 09:08
-
-
Save P1xt/97db232fad48d8beec8b to your computer and use it in GitHub Desktop.
Set Intersection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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