| 136890 | } |
| 136891 | }); |
| 136892 | function nest() { |
| 136893 | const keys = [], nest1 = { |
| 136894 | entries: (array)=>entries(apply(array, 0), 0), |
| 136895 | key: (d)=>(keys.push(d), nest1) |
| 136896 | }; |
| 136897 | function apply(array, depth) { |
| 136898 | if (depth >= keys.length) return array; |
| 136899 | const n = array.length, key = keys[depth++], valuesByKey = {}, result = {}; |
| 136900 | let i = -1, keyValue, value, values; |
| 136901 | while(++i < n){ |
| 136902 | keyValue = key(value = array[i]) + ""; |
| 136903 | if (values = valuesByKey[keyValue]) values.push(value); |
| 136904 | else valuesByKey[keyValue] = [ |
| 136905 | value |
| 136906 | ]; |
| 136907 | } |
| 136908 | for(keyValue in valuesByKey)result[keyValue] = apply(valuesByKey[keyValue], depth); |
| 136909 | return result; |
| 136910 | } |
| 136911 | function entries(map, depth) { |
| 136912 | if (++depth > keys.length) return map; |
| 136913 | const array = []; |
| 136914 | for(const key in map)array.push({ |
| 136915 | key, |
| 136916 | values: entries(map[key], depth) |
| 136917 | }); |
| 136918 | return array; |
| 136919 | } |
| 136920 | return nest1; |
| 136921 | } |
| 136922 | /** |
| 136923 | * Abstract class for tree layout. |
| 136924 | * @constructor |