javascript x times

PHOTO EMBED

Wed Mar 10 2021 02:24:15 GMT+0000 (Coordinated Universal Time)

Saved by @randomuser #javascript

const times = x => f => {
  if (x > 0) {
    f()
    times (x - 1) (f)
  }
}

// use it
times (3) (() => console.log('hi'))

// or define intermediate functions for reuse
let twice = times (2)

// twice the power !
twice (() => console.log('double vision'))
content_copyCOPY

https://stackoverflow.com/questions/30452263/is-there-a-mechanism-to-loop-x-times-in-es6-ecmascript-6-without-mutable-varia