Skip to content

Instantly share code, notes, and snippets.

@darren-rose
Created October 16, 2014 08:06
Show Gist options
  • Save darren-rose/7466240ffa6e2912e616 to your computer and use it in GitHub Desktop.
Save darren-rose/7466240ffa6e2912e616 to your computer and use it in GitHub Desktop.
javascript function creating an array of times every N minute intervals
var everyNminutes = function (n){
var result = [];
for(var hours = 0; hours < 24; hours++){
for(var minutes = 0; minutes < 60; minutes = minutes+n){
var h = '';
var m = '';
if(hours<10){
h = '0' + hours;
}else{
h = hours;
}
if(minutes<10){
m = '0' + minutes;
}else{
m = minutes;
}
result.push(h + ':' + m);
}
}
return result;
};
console.log(everyNminutes(15));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment