Created
July 16, 2016 16:59
-
-
Save danieldiekmeier/bc38936604e53b2b94fcbaec737ee6e2 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
'use strict' | |
var tags = { | |
'a': ['b', 'c', 'd'], | |
'b': ['c', 'd'], | |
'c': ['d'], | |
'd': [], | |
'e': [], | |
'f': ['a'] | |
} | |
let checked = {} | |
for (let v in tags) { | |
if ( | |
typeof checked[v] === 'undefined' && // not checked yet | |
tags[v].length > 0 // does even have children | |
) { | |
if (!transitive(v, tags[v])) { | |
console.log('NOT TRANSITIVE') | |
} | |
} | |
} | |
function transitive(v, rootSubTags) { | |
checked[v] = true | |
for (let i = 0; i < tags[v].length; i++) { | |
let w = tags[v][i] | |
console.log('w:', w, rootSubTags) | |
if (rootSubTags.indexOf(w) === -1) { | |
return false | |
} | |
if (tags[w].length === 0) { | |
return true | |
} | |
console.log('Enter recursion') | |
return transitive(w, rootSubTags) | |
} | |
} | |
console.log('indices:', checked) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment