JSFiddle - React, Tailwind, and code Playground
by chrisJamesC
JavaScript
var data = {
name: "flare",
children: [{
name: "analytics",
children: [{
name: "cluster",
children: [{
name: "AgglomerativeCluster",
size: 3938
}, {
name: "CommunityStructure",
size: 3812
}]
}]
}]
}
function reduce(dataset) {
if ('children' in dataset) {
var tmp = {}
tmp[dataset.name] = $.map(dataset.children, reduce)
return tmp
} else {
return dataset
}
}
var newData = reduce(data)
$("body").text(JSON.stringify(newData))