<<<<<<< HEAD Code Wars - Brett Crafton

Powers of 2

Question

Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ). Examples

n = 0 ==> [1] # [2^0] n = 1 ==> [1, 2] # [2^0, 2^1] n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2]

Solution by -

My Solution


	function powersOfTwo(n){
		let arr=[1]
		for(let i=1; i<=n; i++){
		arr.push(Math.pow(2,i))
		}
		return arr
	}
				

Try it yourself - CodeWars

======= Code Wars - Brett Crafton

Powers of 2

Question

Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ). Examples

n = 0 ==> [1] # [2^0] n = 1 ==> [1, 2] # [2^0, 2^1] n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2]

Solution by -

My Solution


	function powersOfTwo(n){
		let arr=[1]
		for(let i=1; i<=n; i++){
		arr.push(Math.pow(2,i))
		}
		return arr
	}
				

Try it yourself - CodeWars

>>>>>>> 0e614172debaa009c8d31330edbeb3b765b59c39