Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
feat: Simulates roll of a die (#223)
Browse files Browse the repository at this point in the history
Returns a value between 1 and 6

none
  • Loading branch information
rishabkbakshi authored and Kent C. Dodds committed Jan 23, 2019
1 parent 8bd0450 commit 3282f0d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import copyArrayByValue from './copyArrayByValue'
import timeSince from './timeSince'
import first from './first'
import mode from './mode-array'
import rollDice from './rollDice'

export {
reverseArrayInPlace,
Expand Down Expand Up @@ -170,4 +171,5 @@ export {
timeSince,
first,
mode,
rollDice,
}
13 changes: 13 additions & 0 deletions src/rollDice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default rollDice

/**
* Original Source: https://stackoverflow.com/questions/15603217/random-dice-nr-javascript
*
* This method will return a random value from rolling a dice.
*
* @return {number} - Random number between 1 and 6
*/

function rollDice() {
return Math.floor(6 * Math.random()) + 1
}
14 changes: 14 additions & 0 deletions test/rollDice.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import test from 'ava'
import { rollDice } from '../src'

test('Dice value should not be greater than 6', t => {
const max = 6
const diceValue = rollDice()
t.false(diceValue > max)
})

test('Dice value should not be less than 1', t => {
const min = 1
const diceValue = rollDice()
t.false(diceValue < min)
})

0 comments on commit 3282f0d

Please sign in to comment.