Created
September 4, 2018 20:30
-
-
Save RameshRM/a74d64b1f486bee34c85546f81626eb9 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'; | |
const dataset = require('./trie-dataset'); | |
// let wordmap = [{ | |
// name: 'r', | |
// children: [{ | |
// name: 'a', | |
// children: [{ | |
// name: 'm', | |
// isword: true | |
// }, | |
// { | |
// name: 'j', | |
// isword: true | |
// } | |
// ] | |
// }] | |
// }]; | |
let wordmap = { | |
r: { | |
ref: { | |
a: { | |
ref: { | |
m: { | |
isword: true | |
}, | |
j: { | |
isword: true | |
} | |
} | |
} | |
} | |
} | |
}; | |
wordmap = dataset.root.ref.m; | |
var root = wordmap; | |
root.name = 'm'; | |
function build(node, word) { | |
word += node.name; | |
if (node.isWord) { | |
wordList.push(word); | |
} | |
let children = Object.keys(node.ref || {}); | |
if (Array.isArray(children) && children.length > 0) { | |
for (var i = 0; i < children.length; i++) { | |
// console.log(children[i]); | |
node.ref[children[i]].name = children[i]; | |
node.name = children[i]; | |
build(node.ref[children[i]], word); | |
} | |
} | |
return; | |
word += node.name; | |
if (node.children) { | |
for (var i = 0; i < node.children.length; i++) { | |
build(node.children[i], word); | |
} | |
} | |
} | |
var wordList = []; | |
build(root, ""); | |
console.log(wordList); | |
// console.log(root, Object.keys(root.ref)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment