Code trolling - Exponentiation
Help. I need to power the number. I already know how to add, subtract, multiply, and divide, but how can I power numbers? I need this quickly. Plz post the code.
HTML
<pre id="output"></pre>
JavaScript
function out()
{
var args = Array.prototype.slice.call(arguments, 0);
document.getElementById('output').innerHTML += args.join(" ") + "\n";
}
// See http://codegolf.stackexchange.com/questions/17480/code-trolling-exponentation
function power(base, pow)
{
var result = 0;
while (result != Math.pow(base, pow))
{
result++;
}
return result;
}
// Poor-man's unit-testing
out(Math.pow(2, 5));
out(power(2, 5));