Created
April 26, 2016 06:37
-
-
Save codyromano/abb9023cfaf97bb4dc2bf23ef655180d 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
| /** | |
| * @desc Convert an array of strings to a radix tree | |
| * @param {Array} | |
| * @returns {Object} | |
| */ | |
| function radixTree(stringArray) { | |
| return stringArray.reduce(function(result, string) { | |
| var characters = string.split(''), | |
| pointer = result; | |
| characters.forEach(function(char) { | |
| pointer[char] = pointer[char] || {}; | |
| pointer = pointer[char]; | |
| }); | |
| return result; | |
| }, {}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment