FunctionRacerProblemsRace

Multiply It Out

BeginnerRecursionPython, JavaScript, TypeScript, Java, C++

Return base raised to the power exponent, which is base multiplied by itself until it has been used exponent times. Anything to the power 0 is 1, and that includes 0.

The power operator does this in one step, but try the recursive view: a power is base times the same power with an exponent that is one smaller.

Example 1

base 2
exponent 5
returns 32

2 * 2 * 2 * 2 * 2 = 32.

Example 2

base 7
exponent 0
returns 1

The exponent is 0, so nothing is multiplied and the answer is 1.

Example 3

base -3
exponent 3
returns -27

-3 * -3 * -3 = -27. An odd number of negative factors gives a negative result.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems