I am making a simple program that determines what time the next train is. I have an array with all the train times, I just don't know how to determine which is the closest to the current time, without going over. Here is what I have so far:
var d = new Date();
var hours = d.getHours();
var minutes = d.getMinutes();
var time = hours + minutes;
console.log(time);
var trainTimes = [1125, 1155, 1225, 1255, 1325, 1355, 1425, 1455, 1526, 1629, 1644, 1709];
function nextTrain(time) {
}
Within the function nextTrain()
should I simply do if-else statements, or is there a better method?