0

It's a tricky algorithm and data structure challenge I don't find the answer to.

I have an array of objects, my goal is to get the name of them to group them under one object that's contained an array of all the others and put it in an object.

This is the code that i got(the Input)

  [
      { name: ethan, selected: false, text: "test" },
      { name: ethan, selected: false, text: "testlol" },
      { name: yossi, selected: false, text: "test2" },
      { name: yossi, selected: false, text: "test4" },
      { name: yossi, selected: false, text: "test5" },
      { name: shlomi, selected: false, text: "test2" },
      { name: shlomi, selected: false, text: "test4" },
      { name: shlomi, selected: false, text: "test5" },
    ];

Output expected after passing in my function.

   {
  ethan: [
    { text: "test", selected: false },
    { text: "testlol", selected: false },
  ];
  yossi: [
    { text: "test2", selected: false },
    { text: "test4", selected: false },
    { text: "test5", selected: false },
  ];
  shlomi: [
    { text2: "test2", selected: false },
    { text: "test4", selected: false },
    { text: "test5", selected: false },
  ];
}

All that I tried didn't work hope for help

0 Answers0