function fast_expt(b, n) {
return fast_expt_iter(b, n, 1);
}
function fast_expt_iter(b, counter, product) {
return counter === 0
? product
: is_even(counter)
? fast_expt_iter(b * b, counter/2, product)
: fast_expt_iter(b, counter-1, b* product);
}
function sqaure(n) {
return n * n;
}
function is_even(n) {
return n % 2 === 0;
}
728x90