This question is a continuation of the previous inquiry.
View Previous Question
My objective now is to tweak the answer provided earlier. Specifically, I am looking to extract only certain columns instead of all. How should I go about making this adjustment? Thank you.
Data Source: https://i.sstatic.net/yAiZy.png
Expected Outcome:
https://i.sstatic.net/8tDZT.png
Reviewing the solution from the previous question:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('sheetName');
var [_, ...data] = sheet.getDataRange().getValues();
const order = ['First', 'Second', 'Third']
const sorted = data.sort((a, b) => {
const i1 = order.indexOf(a[0]);
const i2 = order.indexOf(b[0]);
const len = data.length;
return 1 * ((i1 > -1 ? i1 : len) - (i2 > -1 ? i2 : len));
});
const merged = sorted.reduce((o, [a, ...b]) => {
if (o.temp != a) {
o.merged.push(a);
o.temp = a;
}
o.merged.push(`- ${b.join(",")}`);
return o;
}, { merged: [], temp: "" }).merged.join("\n");
console.log(merged)
var email = ''
var Subject = "data";
var Message = "Hello ", \n" + "\n" +
"Here is the list of selected data:\n" + merged + "\n" + "\n";
MailApp.sendEmail(email, Subject, Message);
}