MCPcopy
hub / github.com/microsoft/SandDance / nest

Function nest

docs/app/js/sanddance-app.js:136892–136921  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136890 }
136891});
136892function 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

Callers 1

transformFunction · 0.70

Calls 2

entriesFunction · 0.70
applyFunction · 0.70

Tested by

no test coverage detected