Skip to content

Instantly share code, notes, and snippets.

@codyromano
Created April 26, 2016 06:37
Show Gist options
  • Select an option

  • Save codyromano/abb9023cfaf97bb4dc2bf23ef655180d to your computer and use it in GitHub Desktop.

Select an option

Save codyromano/abb9023cfaf97bb4dc2bf23ef655180d to your computer and use it in GitHub Desktop.
/**
* @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