Skip to content

Instantly share code, notes, and snippets.

@danieldiekmeier
Created July 16, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldiekmeier/bc38936604e53b2b94fcbaec737ee6e2 to your computer and use it in GitHub Desktop.
Save danieldiekmeier/bc38936604e53b2b94fcbaec737ee6e2 to your computer and use it in GitHub Desktop.
'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