For instance,
const a = {
'pt-BR': { food: 'Comida', blue: 'Azul' },
'en-US': { food: 'Food', blue: 'Blue' },
};
const b = {
food: { 'pt-BR': 'Comida', 'en-US': 'Food' },
blue: { 'pt-BR': 'Azul', 'en-US': 'Blue' },
};
Initial solution:
Object.entries(a).forEach(([lang, translations]) => {
Object.entries(translations).forEach(([word, translation]) => {
b[word] = { ...b[word], [lang]: translation };
});
});
Is there a better way to transfrom a
into b
that hides these forEach loops? Maybe using lodash
?