function sortNamedRanges() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName('SHEETNAME'); //
const dataRange = ws.getRange(2, 1, ws.getLastRow() - 1, 1);
//"flat" stolen-borrowed from: https://1loc.dev/ (great site! 1loc = one line of code) const flat = (arr) => arr.reduce((a, b) => (Array.isArray(b) ? [...a, ...flat(b)] : [...a, b]), []);
let names = flat(dataRange.getValues());
const myFunction = (value, index, array) => { //I'm trying to learn to use this style
if (value) {
return value + 1;
}
if (!value && !array[index + 1] && array[index - 1]) {
return array[index] = array[index - 1] + 2
}
if (!value && array[index + 1] && array[index - 1]) {
return array[index] = array[index - 2] + 3
}
}
const names2 = names.map(myFunction);
console.log(names2)
}