Created
August 28, 2017 17:28
-
-
Save Woodsphreaker/ca2efd1fbca3097265b2e2e4a0cf4565 to your computer and use it in GitHub Desktop.
pow-js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const n = (y) => [...Array(y).keys()] | |
const calc = (x) => (acc) => acc *= x | |
const pow = (y, x) => n(y).reduce(calc(x), 1) | |
console.log(`3 ^ 1 = ${pow(1, 3)}`) // 3 | |
console.log(`3 ^ 2 = ${pow(2, 3)}`) // 9 | |
console.log(`3 ^ 3 = ${pow(3, 3)}`) // 27 | |
console.log(`3 ^ 4 = ${pow(4, 3)}`) // 81 | |
console.log(`3 ^ 5 = ${pow(5, 3)}`) // 243 | |
console.log(`3 ^ 6 = ${pow(6, 3)}`) // 729 | |
console.log(`3 ^ 7 = ${pow(7, 3)}`) // 2187 | |
console.log(`3 ^ 8 = ${pow(8, 3)}`) // 6561 | |
console.log(`3 ^ 9 = ${pow(9, 3)}`) // 19683 | |
console.log(`3 ^ 10 = ${pow(10, 3)}`) // 59049 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/suissa/Curso-JavaScript-Super-Sayajin