const flat = (arr) => arr.reduce((a, b) => (Array.isArray(b) ? [...a, ...flat(b)] : [...a, b]), []); //this function converts a 2-dimensional array to a 1-D array
const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b); //this function compares two arrays for equality
function CopyTodayHI1() {
const ss = SpreadsheetApp.getActive();
const ranking_Sheet = ss.getSheetByName('Ranking'); //get ranking sheet
const ThatDayHI_Sheet = ss.getSheetByName('ThatDayHI'); //get ThatDayHi sheet
const lastDataRow = ThatDayHI_Sheet.getDataRange().getNumRows(); //find the last row of data on ThatDayHi sheet
const lastHI = flat(ThatDayHI_Sheet.getRange(lastDataRow,5,1,22).getValues()); //get the last row
const currentHI = flat(ranking_Sheet.getRange('B3:W3').getValues()); //get the current values
//compare last data row to current values
if (isEqual(lastHI, currentHI)) {
return; //if they are equal return and do nothing
} else {
ThatDayHI_Sheet.appendRow([,,,, ...currentHI]) //otherwise, append the current ranking to the ThatDayHi sheet
}
};