JSFiddle - React, Tailwind, and code Playground
JavaScript
var data = [
[{
"nome": "SIM",
"valor": 364
}, {
"nome": "NÃO",
"valor": 3877
}, {
"nome": "",
"valor": 12
}]
];
var flat = data.reduce(function(arr, _arr) {
return arr.concat(_arr);
}, []);
var limpa = flat.filter(function(el) {
return el.nome;
});
var total = limpa.reduce(function(tot, el) {
return tot + el.valor;
}, 0);
var percentagens = limpa.map(function(voto) {
return {
nome: voto.nome,
percentagem: voto.valor * 100 / total + '%'
};
});
alert(JSON.stringify(percentagens, null, 4));