-1

I have function in ts

 export function minutesToHoursAndMinutes(m, zeroPadded) {
    if (zeroPadded == null) { zeroPadded = false; }
    let hours:any = Math.floor(m / 60);
    if (zeroPadded && (`${hours}`.length === 1)) { hours = `0${hours}`; }
    let minutes:any = m % 60;
    if (zeroPadded && (`${minutes}`.length === 1)) { minutes = `0${minutes}`; }
    if ((hours === 24) && (minutes === '00')) {
      hours = 23;
      minutes = 59;
    }
    return [hours, minutes];
  };

And try to use it like this

if (("#t-time-range").length > 0) {
$("#t-time-range").slider({
  range: "min",
  value: filter_max.max_traveltime,
  min: filter_max.min_traveltime,
  max: filter_max.max_traveltime+15,
  step: 15,
  slide(event, ui) {
    const hms = FilterFunctions.minutesToHoursAndMinutes(ui.value );
    $("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
    return $('#filter_travel_time').val(ui.value);
  }
});
const hms = FilterFunctions.minutesToHoursAndMinutes($("#t-time-range").slider("value"));
$("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
$('#filter_travel_time').val($("#t-time-range").slider("value"));

}

But I have error about argues

Like this

Expected 2 arguments, but got 1.

How I can make 2 argument optional?

freedomn-m
  • 24,983
  • 7
  • 32
  • 55
Balance
  • 461
  • 2
  • 9
  • 21

3 Answers3

0

try changing the last property of your slider object to

slide: function(event, ui) {
    const hms = FilterFunctions.minutesToHoursAndMinutes(ui.value );
    $("#t-time").val(`Max ${hms[0]}t ${hms[1]}m`);
    return $('#filter_travel_time').val(ui.value);
}
0

Perhaps setting a default value such as

export function minutesToHoursAndMinutes(m, zeroPadded=null).

This way the value is already set, and if you do not pass an argument, it will default to the null value.

0

? makes argument optional. Reference.
export function minutesToHoursAndMinutes(m, zeroPadded?) {

3rdthemagical
  • 5,073
  • 16
  • 34