let step = (base, exponent) => {
exponent = exponent || 2;
/* Ternary operator(other way):
* (exponent == undefined) ? exponent = 2 : exponent;
*/
let res = 1;
for (let c = 0; c < exponent; c++)
res *= base;
return res;
}
// Examples:
step(2) // -> 4
step(2,2) // -> 4
step(1.5) // -> 2.25
step(-2,4) // -> 16
step(-1.5,3) // -> -3.375
step(1.1, 2) // -> 1.2100000000000002; must fix it with toFixed(3)
step(1.1, 3) // -> 1.3310000000000004; must fix it with toFixed(3)
Last active
November 9, 2017 12:54
-
-
Save RinatValiullov/0e672acd5c212e983039e4f269554fbc to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment