Skip to content

Instantly share code, notes, and snippets.

@hbhutta
Created March 8, 2025 22:16
Show Gist options
  • Save hbhutta/d486deafadb27cc82a5d55fb41609eba to your computer and use it in GitHub Desktop.
Save hbhutta/d486deafadb27cc82a5d55fb41609eba to your computer and use it in GitHub Desktop.
min and max in js/ts using reduce
function max(nums: number[]): number {
return nums.reduce((p,v) => {return p>v? p:v;})
}
function min(nums: number[]): number {
return nums.reduce((p,v) => {return p<v? p:v;})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment