Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created August 28, 2017 17:28
Show Gist options
  • Save Woodsphreaker/ca2efd1fbca3097265b2e2e4a0cf4565 to your computer and use it in GitHub Desktop.
Save Woodsphreaker/ca2efd1fbca3097265b2e2e4a0cf4565 to your computer and use it in GitHub Desktop.
pow-js
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
@suissa
Copy link

suissa commented Aug 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment