How To Sum Values And Push To Matching Object In Vue










1















So I am trying to create a computed property that will create a new Array of Objects



My issue is how can I sum the number of values that match a certain value and then push that value into the matching object?



The value I need pushed is count:. I am trying to count the number of objects that match each status value in each workflow object from a separate array called engagements.



I have created a Jsfiddle Click Here



The Array should look like this after being computed



var arr = [
workflow_id: 1,
statuses: [
status: "Received", count: 3,
status: "Review", count: 2,
status: "complete", count: 4
]
,
workflow_id: 2,
statuses: [
status: "Received", count: 3,
status: "Review", count: 1,
status: "complete", count: 1
]
,
workflow_id: 3,
statuses: [
status: "Received", count: 3,
status: "Data Entry", count: 2,
status: "complete", count: 1
]
,
]


any help would be greatly appreciated or a point in a direction that could help me solve this issue! thanks










share|improve this question


























    1















    So I am trying to create a computed property that will create a new Array of Objects



    My issue is how can I sum the number of values that match a certain value and then push that value into the matching object?



    The value I need pushed is count:. I am trying to count the number of objects that match each status value in each workflow object from a separate array called engagements.



    I have created a Jsfiddle Click Here



    The Array should look like this after being computed



    var arr = [
    workflow_id: 1,
    statuses: [
    status: "Received", count: 3,
    status: "Review", count: 2,
    status: "complete", count: 4
    ]
    ,
    workflow_id: 2,
    statuses: [
    status: "Received", count: 3,
    status: "Review", count: 1,
    status: "complete", count: 1
    ]
    ,
    workflow_id: 3,
    statuses: [
    status: "Received", count: 3,
    status: "Data Entry", count: 2,
    status: "complete", count: 1
    ]
    ,
    ]


    any help would be greatly appreciated or a point in a direction that could help me solve this issue! thanks










    share|improve this question
























      1












      1








      1








      So I am trying to create a computed property that will create a new Array of Objects



      My issue is how can I sum the number of values that match a certain value and then push that value into the matching object?



      The value I need pushed is count:. I am trying to count the number of objects that match each status value in each workflow object from a separate array called engagements.



      I have created a Jsfiddle Click Here



      The Array should look like this after being computed



      var arr = [
      workflow_id: 1,
      statuses: [
      status: "Received", count: 3,
      status: "Review", count: 2,
      status: "complete", count: 4
      ]
      ,
      workflow_id: 2,
      statuses: [
      status: "Received", count: 3,
      status: "Review", count: 1,
      status: "complete", count: 1
      ]
      ,
      workflow_id: 3,
      statuses: [
      status: "Received", count: 3,
      status: "Data Entry", count: 2,
      status: "complete", count: 1
      ]
      ,
      ]


      any help would be greatly appreciated or a point in a direction that could help me solve this issue! thanks










      share|improve this question














      So I am trying to create a computed property that will create a new Array of Objects



      My issue is how can I sum the number of values that match a certain value and then push that value into the matching object?



      The value I need pushed is count:. I am trying to count the number of objects that match each status value in each workflow object from a separate array called engagements.



      I have created a Jsfiddle Click Here



      The Array should look like this after being computed



      var arr = [
      workflow_id: 1,
      statuses: [
      status: "Received", count: 3,
      status: "Review", count: 2,
      status: "complete", count: 4
      ]
      ,
      workflow_id: 2,
      statuses: [
      status: "Received", count: 3,
      status: "Review", count: 1,
      status: "complete", count: 1
      ]
      ,
      workflow_id: 3,
      statuses: [
      status: "Received", count: 3,
      status: "Data Entry", count: 2,
      status: "complete", count: 1
      ]
      ,
      ]


      any help would be greatly appreciated or a point in a direction that could help me solve this issue! thanks







      javascript arrays object vue.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 '18 at 18:57









      TJ WeemsTJ Weems

      147110




      147110






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You needed to use Array#reduce on your statuses to create a new array of statuses (to avoid mutating the original) and then within each iteration to Array#filter through the engagements and count those that match the workflow_id and the status.






          const workflows = [
          id: 1,
          workflow: 'bookeeping',
          statuses: [
          status: 'Received'
          ,

          status: 'Prepare'
          ,

          status: 'Review'
          ,

          status: 'Complete'
          ,
          ]
          ,

          id: 2,
          workflow: 'payroll',
          statuses: [
          status: 'Received'
          ,

          status: 'Scan'
          ,

          status: 'Enter Data'
          ,

          status: 'Review'
          ,

          status: 'Complete'
          ,
          ]
          ,

          id: 3,
          workflow: 'tax preparation',
          statuses: [
          status: 'Received'
          ,

          status: 'Scan'
          ,

          status: 'Prep'
          ,

          status: 'Review'
          ,

          status: 'Complete'
          ,
          ]
          ,
          ];
          const engagements = [
          engagement: '1040',
          workflow_id: 1,
          status: 'Received'
          ,

          engagement: '1040',
          workflow_id: 1,
          status: 'Received'
          ,

          engagement: '1040',
          workflow_id: 1,
          status: 'Review'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Review'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Complete'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Complete'
          ,

          engagement: '1040',
          workflow_id: 3,
          status: 'Prep'
          ,

          engagement: '1040',
          workflow_id: 3,
          status: 'Prep'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Enter Data'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Enter Data'
          ,

          engagement: '1040',
          workflow_id: 2,
          status: 'Enter Data'
          ,

          engagement: '1040',
          workflow_id: 1,
          status: 'Prepare'
          ,

          engagement: '1040',
          workflow_id: 1,
          status: 'Prepare'
          ,
          ];

          const res = workflows.map((statuses, id) => (
          workflow_id: id,
          statuses: statuses.reduce((acc, cur) =>

          const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

          if(count === 0) return acc;

          acc.push(status: cur.status, count);

          return acc;

          , )
          ))

          console.log(res);








          share|improve this answer




















          • 1





            thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

            – TJ Weems
            Nov 11 '18 at 20:15


















          0














          Grab the code and analize it :)



          function sumProps(arr) 
          const result =
          for(const el of arr)
          const obj = result.find(e => e.workflow_id === el.workflow_id)
          if (!obj)
          result.push(
          workflow_id: el.workflow_id,
          statuses: [
          status: el.status,
          count: 1
          ]
          )
          continue

          const status = obj.statuses.find(s => s.status === el.status)
          if (!status)
          obj.statuses.push(
          status: el.status,
          count: 1
          )
          continue

          status.count += 1

          return result






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252110%2fhow-to-sum-values-and-push-to-matching-object-in-vue%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You needed to use Array#reduce on your statuses to create a new array of statuses (to avoid mutating the original) and then within each iteration to Array#filter through the engagements and count those that match the workflow_id and the status.






            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);








            share|improve this answer




















            • 1





              thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

              – TJ Weems
              Nov 11 '18 at 20:15















            1














            You needed to use Array#reduce on your statuses to create a new array of statuses (to avoid mutating the original) and then within each iteration to Array#filter through the engagements and count those that match the workflow_id and the status.






            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);








            share|improve this answer




















            • 1





              thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

              – TJ Weems
              Nov 11 '18 at 20:15













            1












            1








            1







            You needed to use Array#reduce on your statuses to create a new array of statuses (to avoid mutating the original) and then within each iteration to Array#filter through the engagements and count those that match the workflow_id and the status.






            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);








            share|improve this answer















            You needed to use Array#reduce on your statuses to create a new array of statuses (to avoid mutating the original) and then within each iteration to Array#filter through the engagements and count those that match the workflow_id and the status.






            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);








            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);





            const workflows = [
            id: 1,
            workflow: 'bookeeping',
            statuses: [
            status: 'Received'
            ,

            status: 'Prepare'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 2,
            workflow: 'payroll',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Enter Data'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,

            id: 3,
            workflow: 'tax preparation',
            statuses: [
            status: 'Received'
            ,

            status: 'Scan'
            ,

            status: 'Prep'
            ,

            status: 'Review'
            ,

            status: 'Complete'
            ,
            ]
            ,
            ];
            const engagements = [
            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Received'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Review'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Complete'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 3,
            status: 'Prep'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 2,
            status: 'Enter Data'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,

            engagement: '1040',
            workflow_id: 1,
            status: 'Prepare'
            ,
            ];

            const res = workflows.map((statuses, id) => (
            workflow_id: id,
            statuses: statuses.reduce((acc, cur) =>

            const count = engagements.filter((workflow_id, status) => workflow_id === id && status === cur.status).length;

            if(count === 0) return acc;

            acc.push(status: cur.status, count);

            return acc;

            , )
            ))

            console.log(res);






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 '18 at 19:30

























            answered Nov 11 '18 at 19:22









            kemicofakemicofa

            9,92543881




            9,92543881







            • 1





              thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

              – TJ Weems
              Nov 11 '18 at 20:15












            • 1





              thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

              – TJ Weems
              Nov 11 '18 at 20:15







            1




            1





            thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

            – TJ Weems
            Nov 11 '18 at 20:15





            thank you so much for the help. I was trying to make things way to complicated. seeing it like this helps me make more sense of what is happening. Thank you

            – TJ Weems
            Nov 11 '18 at 20:15













            0














            Grab the code and analize it :)



            function sumProps(arr) 
            const result =
            for(const el of arr)
            const obj = result.find(e => e.workflow_id === el.workflow_id)
            if (!obj)
            result.push(
            workflow_id: el.workflow_id,
            statuses: [
            status: el.status,
            count: 1
            ]
            )
            continue

            const status = obj.statuses.find(s => s.status === el.status)
            if (!status)
            obj.statuses.push(
            status: el.status,
            count: 1
            )
            continue

            status.count += 1

            return result






            share|improve this answer



























              0














              Grab the code and analize it :)



              function sumProps(arr) 
              const result =
              for(const el of arr)
              const obj = result.find(e => e.workflow_id === el.workflow_id)
              if (!obj)
              result.push(
              workflow_id: el.workflow_id,
              statuses: [
              status: el.status,
              count: 1
              ]
              )
              continue

              const status = obj.statuses.find(s => s.status === el.status)
              if (!status)
              obj.statuses.push(
              status: el.status,
              count: 1
              )
              continue

              status.count += 1

              return result






              share|improve this answer

























                0












                0








                0







                Grab the code and analize it :)



                function sumProps(arr) 
                const result =
                for(const el of arr)
                const obj = result.find(e => e.workflow_id === el.workflow_id)
                if (!obj)
                result.push(
                workflow_id: el.workflow_id,
                statuses: [
                status: el.status,
                count: 1
                ]
                )
                continue

                const status = obj.statuses.find(s => s.status === el.status)
                if (!status)
                obj.statuses.push(
                status: el.status,
                count: 1
                )
                continue

                status.count += 1

                return result






                share|improve this answer













                Grab the code and analize it :)



                function sumProps(arr) 
                const result =
                for(const el of arr)
                const obj = result.find(e => e.workflow_id === el.workflow_id)
                if (!obj)
                result.push(
                workflow_id: el.workflow_id,
                statuses: [
                status: el.status,
                count: 1
                ]
                )
                continue

                const status = obj.statuses.find(s => s.status === el.status)
                if (!status)
                obj.statuses.push(
                status: el.status,
                count: 1
                )
                continue

                status.count += 1

                return result







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 '18 at 19:25









                KonowyKonowy

                359420




                359420



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252110%2fhow-to-sum-values-and-push-to-matching-object-in-vue%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                    How do I collapse sections of code in Visual Studio Code for Windows?

                    ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ