A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
674 B

11 years ago
  1. exports.selectRandomArrayItem = function(array){
  2. return array[Math.floor(Math.random() * array.length)];
  3. };
  4. exports.max = function (value) {
  5. return Math.max.apply(Math, value.map(function (o) {return o.bid;}));
  6. };
  7. // adjusts setTimeout time so it's in sync with actual time intervals
  8. // e.g. 5 minutes intervals will happen at 10:05/10:10/10:15 regardless of start time
  9. // TODO: add the ability to set the interval in seconds / minutes / hours
  10. exports.make_interval = function (interval) {
  11. var d = new Date(), min = d.getMinutes(), sec = d.getSeconds();
  12. return min % interval === 0 && sec === 0 ? 0 : ((60 * (interval - (min % interval))) - sec) * 1000;
  13. };