Please see my comment to the question. Even the formulation of the problem should be written in JavaScript. For example:
var points = [
new Date(2016, 0),
new Date(2018, 1),
new Date(1999, 1),
new Date(302, 0)];
Please see:
Date — JavaScript.
How to compare the points of time? You simply can use the fact the the operators '<' and '>' are defined for the
Date
objects.
The function to calculate both minimum and maximum can, for example, return a stricture with the properties
min
and
max
:
function getMinMaxTime(points) {
if (!points) return undefined;
if (!points.length) return undefined;
if (points.length < 0) return null;
var min = points[0];
var max = points[0];
for (var index in points) {
if (points[index] > max) max = points[index];
if (points[index] < min) min = points[index];
}
return { min: min, max: max };
}
The return for pathological cases when there is no array or the object passed as the argument is not an array or there are no points are just for example. You may decide to do no check-ups, and then deal with possible exceptions, which is also would be a sound decision.
—SA