Last active
December 21, 2016 18:01
-
-
Save ronanyeah/ac5a9a40043930d2b6ff6f8bd2c858ed to your computer and use it in GitHub Desktop.
roll a js dice x times
This file contains 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
'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