Created
September 2, 2022 17:53
-
-
Save grekodev/967376df6791b68f827b010904c83bc9 to your computer and use it in GitHub Desktop.
COMPLETA EL ARRAY DE MESES Y COMPARA SI EL IMPORTE DEL MES ACTUAL ES MAYOR AL MES ANTERIOR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr_mes = [1, 2, 3, 4, 5, 6, 7]; | |
let producto = [{ | |
producto: 'ALEBINO DE PECES', | |
items: [ | |
{mes: 1, importe: '400', is_mayor: false}, | |
{mes: 6, importe: '200', is_mayor: false} | |
] | |
}, | |
{ | |
producto: 'PRODUCTO 2', | |
items: [ | |
{mes: 3, importe: '300', is_mayor: false}, | |
{mes: 4, importe: '400', is_mayor: false}, | |
{mes: 6, importe: '600', is_mayor: false} | |
] | |
}, | |
{ | |
producto: 'ARIEL', | |
items: [ | |
{mes: 7, importe: '600', is_mayor: false} | |
] | |
} | |
] | |
let arr_new_pro = producto.map((pp, pi) => { | |
let pro = {...pp}; | |
let exist_meses = pro.items.map((mv,mi)=>{ | |
return mv.mes; | |
}); | |
let excludes_ele = arr_mes.filter( function( el ) { | |
return !exist_meses.includes( el ); | |
}); | |
excludes_ele.forEach((npv, npi)=>{ | |
pro['items'].push({mes: npv, importe: 0, is_mayor: false}); | |
}); | |
pro['items'].sort(dynamicSort('mes')); | |
for (let ai = 0; ai < pro['items'].length; ai++) { | |
if(ai > 0 && ai < pro['items'].length - 1){ | |
pro['items'][ai+1] = {mes:pro['items'][ai+1].mes, importe:pro['items'][ai+1].importe, is_mayor: parseFloat(pro['items'][ai].importe) < parseFloat(pro['items'][ai+1].importe)}; | |
} | |
} | |
return pro | |
}); | |
console.log(arr_new_pro); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment