const findParents = (id, arr) => {
for (let i = 0, l = arr.length; i < l; ++i) {
const {category: {categoryId, categoryDescription}, children} = arr[i];
const obj = {categoryId, categoryDescription};
if (categoryId === id) {
return [obj];
} else {
const result = findParents(id, children);
if (result) {
return [obj, ...result];
}
}
}
return null;
};