maxOfThree

Easy · Conditionals · 4 test cases

Given three numbers, return the largest one.

Examples

maxOfThree(1, 5, 2) → 5
maxOfThree(10, 5, 2) → 10
maxOfThree(-1, -5, -2) → -1

Starter code

function maxOfThree(a, b, c) {

}

Complexity of the optimal solution

Time O(1), space O(1). The `Math.max` function for a fixed number of arguments (3 in this case) runs in constant time.

Solve maxOfThree in the browser