max function code example
Example 1: max value in array javascript
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });
const max = Math.max.apply(null, arr);
const max = Math.max(...arr);
Example 2: python max()
i = max(2, 4, 6, 3)
print(i)
# Result will be 6 because it is the highest number
Example 3: python max with custom function
nums = [1,2,3,1,1,3,3,4,4,3,5] #list
counts = collections.Counter(nums) # create a dict of counts
#using counts.get() fun as custom function
return max(counts.keys(), key=counts.get)
Example 4: max func in python
max([2, 1, 4, 3])
#Returns 4 as it's the largest integer in the list
Example 5: return max(max(a,b),max(c,d));
return max(max(a,b),max(c,d));