'How to find highest high lowest low values from a range of cell values for every n cells values with google app script

google app script to find highest high and lowest low values from an array of cell values for every n cell values from a range in google sheet. suppose the values in A column are as - A1 1 A2 12 A3 8 A4 2 A5 5 A6 9 A7 6 A8 8 A9 11 A10 10 A11 7 A12 12 A13 5 A14 2 A15 15

As per logic the first highest high value of first five cell values of columan A is as 12, which is on B column's first cell and the first lowest low value of five cell values of columan A is as 1, which is on C column and so on for other call values with every five cell values to find the highest high and lowest low values from A column top to bottom.

Here's the screenshot of google sheet



Solution 1:[1]

Highs and Lows of Active Range List

function highsandlows() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const rgl = sh.getActiveRangeList();
  const fl = rgl.getRanges().map(r => r.getValues().flat()).flat();
  const l = fl.sort((a,b) => a - b)[0];
  const h = fl.sort((a,b) => b - a)[0];
  Logger.log('high: %s, low: %s',h,l);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cooper