Skip to content

Instantly share code, notes, and snippets.

@ndabAP
Last active June 26, 2018 07:17
Show Gist options
  • Save ndabAP/613924c2bba0deae967ceb8f8787b320 to your computer and use it in GitHub Desktop.
Save ndabAP/613924c2bba0deae967ceb8f8787b320 to your computer and use it in GitHub Desktop.
Random alphabetical string with JavaScript
/**
* @see {@url https://stackoverflow.com/questions/30452263/is-there-a-mechanism-to-loop-x-times-in-es6-ecmascript-6-without-mutable-varia#answer-30452949}
*/
const times = x => f => {
if (x > 0) {
f()
times (x - 1) (f)
}
}
let hash = ''
times (3) (() => hash += String.fromCharCode(97 + Math.floor(Math.random() * 25)))
console.log(hash) // e. g. fkq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment