Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var exames = [
{type:"AUR", price:10},
{type:"FOL", price:10},
{type:"GLI", price:10},
{type:"COL", price:30.92},
{type:"USA", price:23.32},
{type:"POT", price:48.13}
];
var copy = exames.map( function( elem ) {
return elem ;
});
var descProporcional = 0;
var somaDesconto = 0;
var vTotalExames = exames.reduce( function( prevVal, elem ) {
return (prevVal + elem.price);
}, 0 );
console.log(vTotalExames);
var vTotalDesconto = 90;
descontoParcial = 0
for (var key in exames) {
descProporcional = exames[key].price / vTotalExames;
valorDescontoRateado = descProporcional * vTotalDesconto;
exames[key].price = (exames[key].price - valorDescontoRateado).toFixed(2);
somaDesconto=somaDesconto+valorDescontoRateado;
// somaValores
}
console.log('------------------------------------------');
console.log('Objeto sem descontos:');
console.log(copy);
console.log('------------------------------------------');
console.log('Objeto com descontos:');
console.log(exames);
console.log('------------------------------------------');
console.log('descoto:' + valorDescontoRateado);
var sum = exames.reduce( function( prevVal, elem ) {
return prevVal + elem.price;
}, 0 );
console.log('Total da nota: ' + vTotalExames);
console.log('Desconto Aplicado: ' + somaDesconto);
console.log('Total da nota Final: ' + sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment