Convert strConflictedYesReviewers data into a single object which is grouped by ownerid and then gro

Discussion in 'JavaScript' started by asifakhtar, Dec 5, 2022.

  1. #1
    Convert strConflictedYesReviewers data into a single object which is grouped by ownerid first and then groupby opportunityid which contains array of response.

    I get a dynamic string(strConflictedYesReviewers) which contains multiple user recordswhere each record is separated by semicolon and then each record represents ownerid and opportunityid separated by asterisk.

    const strConflictedYesReviewers = "88639280*198719943;88642547*198721749;88627345*198721749;88664734*198721749;88686221*198721749;88676217*198721749;88664734*198721749;88686221*198721749;88676217*198721749;"
    .split(";")
    .map(item => item.split("*"))
    .filter(item => !!item[0])
    .map(item => ({ownerid: item[0], opportunityid: item[1]}))
    .reduce(function(acc, curr) {
    (acc[curr["ownerid"]] = acc[curr["ownerid"]] || []).push(curr["opportunityid"]);
    return acc;
    }, {});


    console.log(strConflictedYesReviewers);
    //need the object like the foloowing in the end.
    {
    "68642547": {
    "222": [
    "Yes"
    ]
    },
    "88627345": {
    "111": [
    "No",
    "Yes",
    "No"
    ],
    "222": [
    "Yes"
    ]
    },
    "88642547": {
    "111": [
    "Yes",
    "No"
    ],
    "222": [
    "Yes",
    "No"
    ]
    }
    }
     
    asifakhtar, Dec 5, 2022 IP
  2. asifakhtar

    asifakhtar Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #2
    Hey,
    I apologise, I made a mistake. I copied the incorrect strConflictedYesReviewers at the top.
    The correct one is the following:
    68642547*222*Yes;88627345*111*No;88627345*111*Yes;88627345*111*No;88627345*222*Yes;88642547*111*Yes;88642547*111*No;88642547*222*Yes;88642547*222*No;
     
    asifakhtar, Dec 7, 2022 IP
  3. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #3
    Question is not clear Asifa.
    Please provide clarity on input and output you desire without js code.
    input: .......................
    output: ......................
     
    Vooler, Dec 21, 2022 IP