JavaScript
2
Вклад в тег
const example = (arr) => {
let result = [];
if (Array.prototype.hasOwnProperty.call(arr, 0) && arr[0] instanceof Object)
result.push(arr[0]);
let lastObj = result[0];
for (let i = 1; i < arr.length; ++i) {
const el = arr[i];
if (el && el instanceof Object) {
lastObj.children = el;
lastObj = el;
}
}
return result;
}