DEV Community

Powers of 2

The function `powersOfTwo` calculates powers of 2 from 0 up to a given non-negative integer `n`. It uses a loop to iterate through exponents from 0 to `n`, calculating 2 raised to the power of each exponent. The results are stored in a new array, `newArr`, which is then returned. The function correctly handles input values of 0 and positive integers.
favicon
dev.to
dev.to
Create attached notes ...