-1

This code return:

0: 100,
1: 10,
2: 120,
3: 1

I need to catch the highest and lowest value. Is there any way to do it?. I need a var min = 1 and var max = 120

var activeChoose = $('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]');
  activeChoose.each(function (index, value) {
    if (!$($('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]'))[index].attributes.style) {
      $(this).each(function (fakeIndex, value) {
        console.log(index + ': ' + parseInt(value.innerText));
      })
}});
Varit J Patel
  • 3,497
  • 1
  • 13
  • 21
JSExpress1
  • 35
  • 5

3 Answers3

0

You can use this code:

var activeChoose = $('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]');

var minVal = 0;
var maxVal = 0;
activeChoose.each(function (index, value) {

if (!$($('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]'))[index].attributes.style) {
    $(this).each(function (fakeIndex, value) {
        if(minVal > parseInt(value.innerText)){
            minVal = parseInt(value.innerText);
        }
        if(maxVal < parseInt(value.innerText)){
            maxVal = parseInt(value.innerText);
        }
        console.log(index + ': ' + parseInt(value.innerText));
    })
}
});
Eitbiz
  • 109
  • 6
0

A simple way of getting the min and max values from an array which than you can use their values for your needs.

getMinMax = (arr) => {
  return { min: Math.min(...arr), max: Math.max(...arr) }
}

const { min, max } = getMinMax([10, 1, 100, 120])

console.log(`min: ${min}, max: ${max}`)
omri_saadon
  • 10,193
  • 7
  • 33
  • 58
0

you can create max and min variables and check, if current value is big from max and assign it to max and for min, if current value is small then min

var min = 1;
var max = 0;
var activeChoose = $('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]');
  activeChoose.each(function (index, value) {

  if (!$($('.filter--active-container').find('span[data-filter-param*="sFilterProperties"]'))[index].attributes.style) {
   $(this).each(function (fakeIndex, value) {
   console.log(index + ': ' + parseInt(value.innerText));
   var v = parseInt(value.innerText);
   max = max > v ? max : v;
   min = min > v ? v : min;
})}});
Artyom Amiryan
  • 2,846
  • 1
  • 10
  • 22