Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 779 Bytes

power.md

File metadata and controls

35 lines (25 loc) · 779 Bytes

Power 8 Kyu

LINK TO THE KATA - RESTRICTED

Description

The goal is to create a function of two inputs number and power, that "raises" the number up to power (ie multiplies number by itself power times).

Examples

numberToPower(3, 2)  // -> 9 ( = 3 * 3 )
numberToPower(2, 3)  // -> 8 ( = 2 * 2 * 2 )
numberToPower(10, 6) // -> 1000000

Note: Math.pow and some other Math functions like eval() and ** are disabled.

Solution

const numberToPower = (number, power) => {
  let result = 1

  for (let i = 0; i < power; i++) {
    result *= number
  }

  return result
}