Skip to content

Instantly share code, notes, and snippets.

@ronanyeah
Last active December 21, 2016 18:01
Show Gist options
  • Save ronanyeah/ac5a9a40043930d2b6ff6f8bd2c858ed to your computer and use it in GitHub Desktop.
Save ronanyeah/ac5a9a40043930d2b6ff6f8bd2c858ed to your computer and use it in GitHub Desktop.
roll a js dice x times
'use strict'
// Number -> Object
module.exports = rolls =>
Array.from( Array(rolls) )
.map(
() =>
Math.ceil( Math.random() * 6 )
)
.reduce(
(acc, roll) =>
Object.assign(
acc,
{
[roll]: ( acc[roll] || 0 ) + 1
}
),
{}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment