-3
I have the following code
const dados = [
{ "cnpj": "1234567891011", "serie": "1", "numero": "1" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "2" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "3" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "4" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "5" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "6" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "7" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "9" },
{ "cnpj": "1234567891011", "serie": "1", "numero": "10" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "1" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "2" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "4" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "5" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "6" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "7" },
{ "cnpj": "1213141516171", "serie": "1", "numero": "9" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "10" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "11" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "12" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "15" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "16" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "17" },
{ "cnpj": "1213141516171", "serie": "2", "numero": "21" },
{ "cnpj": "1213141516171", "serie": "3", "numero": "2" },
{ "cnpj": "1213141516171", "serie": "3", "numero": "3" },
{ "cnpj": "1213141516171", "serie": "3", "numero": "5" },
{ "cnpj": "1213141516171", "serie": "3", "numero": "6" },
{ "cnpj": "1213141516171", "serie": "3", "numero": "7" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "22" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "1" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "2" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "3" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "4" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "6" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "7" },
{ "cnpj": "9090909871234", "serie": "1", "numero": "8" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "2" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "1" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "3" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "4" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "5" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "6" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "7" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "8" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "9" },
{ "cnpj": "9090909871234", "serie": "3", "numero": "10" }
];
const organizados = dados.reduce((acumulador, { cnpj, numero }) => {
const copia = { ...acumulador };
copia[cnpj] = [...(copia[cnpj] || []), parseInt(numero, 10)];
return copia;
}, {});
const faltando = Object.keys(organizados).reduce((acumulador, cnpj) => {
const numeros = organizados[cnpj];
const [minimo, maximo] = [Math.min(...numeros), Math.max(...numeros)];
const copia = { ...acumulador };
copia[cnpj] = Array.from(Array(maximo - minimo), (v, indice) => indice + minimo).filter(item => !numeros.includes(item));
return copia;
}, {});
const imprime = (valores) => {
for (let [key, value] of Object.entries(valores)) {
console.log('Cliente:', key);
let serie1 = [], serie2 = [], serie3 = [];
for (let [k, v, s] of Object.entries(value)) {
serie1.push(k);
serie2.push(v);
serie3.push(s);
}
console.log('Serie 1:', serie1.join(', '));
console.log('serie 2:', serie2.join(', '));
console.log('serie 3:', serie3.join(', '));
}
}
console.log('pulou numeros');
imprime(faltando);
which checks where skipped the number separated by CNPJ and serial, the problem is that it is not pulling the number 3 series
Your code doesn’t work
dados is not defined
– Sorack
didn’t work because it doesn’t have the array
– Marcos Paulo
It follows the correction, in which case it was only to take the array of the question.
– João Cota
It’s perfect, but it’s not showing the numbers that jumped, it’s just listing the numbers
– Marcos Paulo
Just add the condition to display.
– João Cota