Last active
May 27, 2020 10:26
-
-
Save vmarchesin/5b60a5e5386030c2f976de916f9e62c5 to your computer and use it in GitHub Desktop.
how-to-publish-a-npm-package
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
const bool = () => Boolean(Math.round(Math.random())); | |
export default bool; |
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
const float = (max, min) => Math.random() * (max - min) + min; | |
export default float; |
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
import bool from './bool'; | |
import float from './float'; | |
import integer from './integer'; | |
const choice = (max = 1, min = 0, options = {}) => { | |
if (options.float === true) { | |
return float(max, min); | |
} else if (options.bool === true) { | |
return bool(); | |
} else { | |
return integer(max, min); | |
} | |
} | |
export default choice; |
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
const integer = (max, min) => ~~(Math.random() * (max - min + 1) + min); | |
export default integer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment