Last active
November 12, 2021 22:38
-
-
Save richardba/2dc78a01a2ffdc3f70f30032d4c1f85f to your computer and use it in GitHub Desktop.
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
function findZeroOrOneParentage(input) | |
{ | |
var objects = {} | |
var set = new Set() | |
input.forEach(function(elem){ | |
if(objects[elem[0]] === undefined) | |
objects[elem[0]] = [] | |
if(objects[elem[1]] === undefined) | |
objects[elem[1]] = [] | |
objects[elem[0]].push(elem[1]) | |
set.add(elem[0]).add(elem[1]) | |
}) | |
var result = [[],[]] | |
set.forEach(function(value) { | |
if(objects[value].length === 0) | |
result[0].push(value) | |
else if(objects[value].length === 1) | |
result[0].push(value) | |
}) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment