11'use strict' ;
2-
3- var exists = function ( obj , key ) {
4- return obj != null && Object . hasOwnProperty . call ( obj , key ) ;
5- } ;
6-
7- var extend = function ( destination , source ) {
8- for ( var property in source ) {
9- destination [ property ] = source [ property ] ;
10- }
11- return destination ;
12- }
13-
14- var isArray = Array . isArray || function ( obj ) {
15- return toString . call ( obj ) === '[object Array]' ;
16- } ;
2+ var isArray = require ( 'isarray' ) ;
3+ var extend = require ( 'shallow-object-extend' ) ;
4+ var exists = require ( 'property-exists' ) ;
175
186var createTree = function ( array , rootNodes , customID ) {
197 var tree = [ ] ;
208
21- for ( var key in rootNodes ) {
22- if ( ! exists ( rootNodes , key ) ) {
9+ for ( var rootNode in rootNodes ) {
10+ if ( ! exists ( rootNodes , rootNode ) ) {
2311 continue ;
2412 }
25- var parentNode = rootNodes [ key ] ;
26- var childNode = array [ parentNode [ customID ] ] ;
13+ var node = rootNodes [ rootNode ] ;
14+ var childNode = array [ node [ customID ] ] ;
2715
2816 if ( childNode ) {
29- parentNode . children = createTree ( array , childNode , customID ) ;
17+ node . children = createTree ( array , childNode , customID ) ;
3018 }
3119
32- tree . push ( parentNode ) ;
20+ tree . push ( node ) ;
3321 }
3422
3523 return tree ;
@@ -53,7 +41,7 @@ var groupByParents = function(array, options) {
5341
5442/**
5543 * arrayToTree
56- * Convert a plain array of nodes (with pointers to parent nodes) to a tree
44+ * Convert a plain array of nodes (with pointers to parent nodes) to a nested data structure
5745 *
5846 * @name arrayToTree
5947 * @function
0 commit comments