Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
¿Cómo puedo calcular la parte en porcentaje para cada usuario que usa loop for?

Tengo dos matrices aquí. Uno de proyectos y otro de plomo. Cada proyecto tiene idLead como clave externa. Ya he creado algunas funciones y están funcionando bien. Ahora solo quiero hacer un bucle en el prospecto para conocer la parte de cada prospecto en los proyectos. Quiero decir, ¿cuántos proyectos tiene cada cliente potencial en %?

 ngOnInit(): void { // This is intentional this.SumOfLead(); this.SumOfProjet(); this.ProjetParAnnee('2020'); this.leadParAnnee(); this.LeadProjetSum('2'); }
 leadList: any = [ { id: '1', libelle: 'Vector', anneeCreation: '2020' }, { id: '2', libelle: 'Salim', anneeCreation: '2021' }, { id: '3', libelle: 'Antoine', anneeCreation: '2020' }, { id: '4', libelle: 'Eya', anneeCreation: '2022' }, { id: '5', libelle: 'Juliette', anneeCreation: '2021' }, { id: '6', libelle: 'Anna', anneeCreation: '2021' }, ]; projetList: any = [ { id: '1', libelle: 'EcoleVector', anneeCreation: '2021', idLead: '1', }, { id: '2', libelle: 'Aramex', anneeCreation: '2021', idLead: '2' }, { id: '3', libelle: 'SpeedFood', anneeCreation: '2021', idLead: '4' }, { id: '4', libelle: 'Jumia', anneeCreation: '2022', idLead: '1' }, { id: '5', libelle: 'Amazon', anneeCreation: '2020', idLead: '5' }, { id: '6', libelle: 'AliBaba', anneeCreation: '2022', idLead: '6' }, { id: '7', libelle: 'TikTok', anneeCreation: '2021', idLead: '3' }, { id: '8', libelle: 'Teskerti', anneeCreation: '2022', idLead: '2' }, ];
 SumOfLead() { let nombreLead = this.leadList.length; console.log(nombreLead, 'nombre de leads'); } SumOfProjet() { let nombreProjet = this.projetList.length; console.log(nombreProjet, 'nombre de projets'); } ProjetParAnnee(annee: string) { let filteredProjet = this.projetList.filter( (list: any) => list.anneeCreation === annee ); console.log(filteredProjet, 'projets crées en 2020'); } leadParAnnee() { let annee = '2021'; let filteredLead = this.leadList.filter( (lead: any) => lead.anneeCreation === annee ); console.log(filteredLead, ' nombre de lead crées en 2021'); } LeadProjetSum(id: any) { let nombreProjet = this.projetList.length; let SumProjetForOneLead = this.projetList.filter((sum: any) => sum.idLead === id); let part = (SumProjetForOneLead.length * 100) / nombreProjet; console.log( SumProjetForOneLead.length, 'nombre de projet par lead ', 'part=', part + '%' ); }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Mejor que crear una función y usarla en .html, agregue una nueva propiedad a LeadList:

 const count=this.projetList.length; this.leadList.forEach(x=>{ x.part=this.projetList.filter(y=>y.idLead==x.id).length/count*100.0 })

o puede crear una matriz countProjects

 const countProject=this.projetList.reduce((a,b)=>{ const el=a.find(x=>x.id==b.idLead); if (!el) a.push({id:b.idLead,count:1}) else el.count++ return a },[]) //and use this.leadList.forEach(x=>{ const counter=countProject.find(y=>y.id==x.id) x.part=counter?counter.count/count*100.0:0 })
about 4 years ago · Juan Pablo Isaza Relatório

0

gracias a todos lo hice, es solo un bucle fácil

 leadProjetSum() { const nombreProjet = this.projetList.length; for (let lead of this.leadList) { let SumProjetByLead = this.projetList.filter( (project: any) => project.idLead === lead.id ); const partlead = (SumProjetByLead.length * 100) / nombreProjet; console.log( lead.libelle, ':nombre de projets =', SumProjetByLead.length, ':part est =', partlead + '%' ); } }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda