-
-
Save gf3/381153 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
userData = { | |
'person1' : [1,2,3,4], | |
'person2' : [3,4,5,6] | |
} | |
function returns | |
{ | |
'person1': {'person2': [3, 4]}, | |
'person2': {'person1': [3, 4]} | |
} | |
*/ | |
function calculateRelations(userData) { | |
sys.puts('calc'); | |
var start = new Date().getTime() / 100; | |
var matches = {}; | |
for (key in userData) { | |
matches[key] = {}; | |
for (subKey in userData) { | |
if (key !== subKey) { | |
for (var i = 0, l = userData[key].length; i < l; i++) { | |
for (var u = 0, le = userData[key].length; u < le; u++) { | |
if (userData[key][i] === userData[subKey][u]) { | |
if (!matches[key][subKey]) { | |
matches[key][subKey] = []; | |
} | |
matches[key][subKey].push(userData[subKey][u]); | |
} | |
} | |
}; | |
} | |
} | |
} | |
var end = new Date().getTime() / 100; | |
sys.p('Calculation took: ' + (end - start) + 'sec'); | |
return matches; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment