Skip to content

Instantly share code, notes, and snippets.

@fieldse
Last active March 6, 2025 08:10
Show Gist options
  • Save fieldse/fb88c814c9251062f50012b677117501 to your computer and use it in GitHub Desktop.
Save fieldse/fb88c814c9251062f50012b677117501 to your computer and use it in GitHub Desktop.
Get the largest element from an integer array in Typescript using `reduce()`

Get largest element from integer array in Typescript

// Return highest element from array
const getMax = (arr: number[]): number =>
  arr.reduce((max, current) => {
    return current > max ? current : max;
  }, arr[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment