We have a remove duplicates function that removes rows that are previously duplicated, i.e., where Row 2, comprising B1 and B2, is deleted if B1 and B2 are identical to Row 1's A1 and A2. But we want it to be such that Row 2 is deleted only if B2 is identical to A2. Here is the code we have thus far:
function removeDuplicates() {
const startTime = new Date();
const newData = [];
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getDataRange().getValues();
const numRows = data.length;
const seen = {};
for (var i = 0, row, key; i < numRows && (row = data[i]); i++) {
key = JSON.stringify(row);
if (key in seen) {
continue;
}
seen[key] = true;
newData.push(row);
};
The function should only affect latter rows and not former rows (i.e., Row 2 should be deleted, and not Row 1).