Created
March 8, 2025 22:16
-
-
Save hbhutta/d486deafadb27cc82a5d55fb41609eba to your computer and use it in GitHub Desktop.
min and max in js/ts using reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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