DEV Community

loading...

Discussion on: Daily Challenge #306 - Largest Possible Product

Collapse
willsmart profile image
willsmart

A KISS version in typescript...

function greatestProductOfAdjacentPair(arr: number[]): number | undefined {
  let max: number | undefined;
  for (let i = arr.length - 2; i >= 0; i--) {
    max = Math.max(max ?? -Infinity, arr[i] * arr[i + 1]);
  }
  return max;
}
Enter fullscreen mode Exit fullscreen mode