Skip to content

Instantly share code, notes, and snippets.

@schovi
Created March 29, 2013 11:36
Show Gist options
  • Save schovi/5270342 to your computer and use it in GitHub Desktop.
Save schovi/5270342 to your computer and use it in GitHub Desktop.
// Generator
function timeDataGenerator(interval) {
var times = [];
for (x = 0; x < 24; x++) {
if (x.toString().length === 1) { var hours = "0"+x; }
else { var hours = x; }
for (y = 0; y < 60; y+=interval) {
if (y.toString().length === 1) { var minutes = "0"+y; }
else { var minutes = y; }
times.push(hours+":"+minutes);
}
}
return times;
}
// Matcher
var timeData = timeDataGenerator(5)
function matchTime(req) {
var matcher = new RegExp( "^0?" + req, "i" ),
result = $.grep(timeData, function(item,index){
return matcher.test(item);
});
return result;
}
matchTime("10:") -> ["10:00", "10:05",....., "10:55"]
matchTime("10:3") -> ["10:30", "10:35"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment