Guest User

Untitled

a guest
Feb 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. var lista = JSON.parse(data);
  2. var listaEmpreendimentos = [];
  3. lista.map(item => {
  4. if (item.oportunidade.empreendimento) {
  5. var index = listaEmpreendimentos.findIndex(
  6. i =>
  7. i.oportunidade.empreendimento ===
  8. item.oportunidade.empreendimento &&
  9. i.oportunidade.datavenda === item.oportunidade.datavenda
  10. );
  11. if (index !== -1) {
  12. listaEmpreendimentos[index].composicao = listaEmpreendimentos[
  13. index
  14. ].composicao.concat(
  15. item.composicao
  16. .filter(f => f.tipoparticipante === "Gerente")
  17. .map(m => m.nome)
  18. );
  19. } else {
  20. listaEmpreendimentos.push({
  21. oportunidade: {
  22. empreendimento: item.oportunidade.empreendimento,
  23. datavenda: item.oportunidade.datavenda
  24. },
  25. composicao: item.composicao
  26. .filter(f => f.tipoparticipante === "Gerente")
  27. .map(m => m.nome)
  28. });
  29. }
  30. }
  31. });
  32. console.log(listaEmpreendimentos);
  33. });
Add Comment
Please, Sign In to add comment