I'm working with a large sheet of duplicated names, but with unique data in the cells next to the name. I need to remove the duplicate names and append the additional unique data to the end of the first-named row. I'll include screenshots to explain what I mean:
I have an array similar to this: [John Smith, General], [John Smith, Tall], [John Smith, Rich], [John Smith, Blue], [John Smith, Children], [John Smith, Tall], [John Smith, Rich]
I need to turn it into this: [John Smith, (General, Tall, Rich, Blue, Children)]
I'm pretty new to javascript/app script and I'm having a hard time wrapping my head around this. This is my current thought process:
var filteredData = []
for (var i = 0; i < peopleData.length; i++){
//If name doesn't exist on filtered list, add it
if (filteredData.indexOf(peopleData[i][0]) == -1){
filteredData.push([peopleData[i][0], peopleData[i][1]]);
}
else{
//Name already exists, add attributes to existing entry
filteredData[i-1] = filteredData[i-1] + ", " + peopleData[i][1];
}
}
Any pointers would be greatly appreciated. Thanks