Sum Obj Recursivamente
JavaScript
let data = {
start: {
preview: {
height:2,
padding: {
top: 2,
bottom: 2
}
},
title: {
height: 2
},
iframe: {
height: 2
}
}
}
const sumObj = obj => Object.keys(obj).reduce((sum, next) => typeof obj[next] === 'object' ? sum + sumObj(obj[next]) : sum + obj[next], 0)
console.log(sumObj(data))