https://www.codewars.com/kata/562926c855ca9fdc4800005b
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
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.
코드
function numberToPower(number, power){
console.info(Math.log2(1024));
// Code here
let result = 1;
let i = 0;
while(i < power){
result *= number;
i++;
}
return result;
}
댓글