Powers of 2

The function “powersOfTwo” takes a non-negative integer as input and returns a list of powers of 2 with exponents ranging from 0 to n inclusive. It creates an array of length n and uses a for loop to calculate 2 raised to the power of i for each i from 0 to n. The calculated values are then added to a new array and returned as the result.

Read Original

Scroll to Top