utils.js 442 B

12345678910111213141516171819202122
  1. function randomInt (min, max) {
  2. return min + Math.round(Math.random() * max);
  3. }
  4. function getRandomArrayValue (source) {
  5. if (!(source && source.length)) {
  6. return;
  7. }
  8. const randomIndex = randomInt(0, source.length - 1);
  9. return source[randomIndex];
  10. }
  11. function capitalize (str) {
  12. return str && str[0].toUpperCase() + str.substr(1);
  13. }
  14. module.exports = {
  15. randomInt,
  16. getRandomArrayValue,
  17. capitalize
  18. };