-1

I am trying to get the lowest time value out of the 3 results that's being generated by a Stopwatch with Lap.

The result of the code below can show the time values in these format: 00:00:56 00:02:34 00:02:15

So, I replaced/removed the Colon(:) in order to work with min,max.

I am trying to send the lowest value as part of the form.

$(".submit").click(function(){
    var time_trial = [];

   $('.laps li').each(function (n) {
        time_trial[n] = $(this).html().replace(/:/g, '');
    });
    return false;
});

enter image description here

Romanov
  • 41
  • 1
  • 7
  • _“in order to work with min,max”_ - and where exactly is your attempt to do that? _“as part of the form”_ - what form? The HTML you have shown doesn’t contain any form elements, so there must be more to this than what you have shown us? Proper [mre] of your issue, please - always! – CBroe Aug 28 '20 at 10:36

1 Answers1

1

Because you give us not informations I assume to have the times as an array in format HH:MM:SS. You could useing the date-functionn for the compare of this, I use the mathematical approach.
Using Array#map to transform each entry of the array. For this I add before the converted timestring (without the ':') the string '1' and use parseInt to get a valid Integer (therefore the 1 because otherwise the leading zeros make problems).
On the resulting array of integers I use Math.min to get the minimum and convert it back to string with toString. At last I use subStr to build the valid format of your timestring.

let times = ['00:00:56', '00:02:34', '00:02:15'];

let res = Math.min(...times.map(t => parseInt('1'+t.replace(/:/g, '')))).toString();
res = res.substr(1,2) + ':' + res.substr(3,2) + ':' + res.substr(5);

console.log( res);
Sascha
  • 4,576
  • 3
  • 13
  • 34