checkSign

Easy · Conditionals · 3 test cases

Given a number, return 'positive' if the number is greater than 0, 'negative' if it's less than 0, and 'zero' if it is 0.

Examples

checkSign(10) → 'positive'
checkSign(-5) → 'negative'
checkSign(0) → 'zero'

Starter code

function checkSign(num) {

}

Complexity of the optimal solution

Time O(1), space O(1). The function performs a maximum of two comparisons to determine the result. This is a constant time operation.

Solve checkSign in the browser