How to find the smallest and largest number from a list of number?

Not applicable

Scenario: I have retrieved some numbers by gliderecord and stored in a variable, now i have to find the smallest and largest number from that  list by using below code but it is not working.

var x = 1,2,3,4,5,6    //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = [x];
var min = Math.min.apply(Math,array);
gs.info(min);
1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

If you have stored those values as string then you can use below script :

var x= "1,22,8,3,4,5,6";  //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = x.split(",");
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);

If you have stored those values as array of numbers then you can use below script :

var array = [1,22,8,3,4,5,6];  //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022

View solution in original post

3 REPLIES 3

Maik Skoddow
Tera Patron

Hi

please use

var arrNumbers = [1,22,8,3,4,5,6];

gs.info(Math.max.apply(null, arrNumbers));

Maik

Yousaf
Giga Sage

Abhijit4
Mega Sage

If you have stored those values as string then you can use below script :

var x= "1,22,8,3,4,5,6";  //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var array = x.split(",");
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);

If you have stored those values as array of numbers then you can use below script :

var array = [1,22,8,3,4,5,6];  //(This is list of numbers which i found from gliderecord and output is same as in variable x)
var min = Math.min.apply(null,array);
gs.print(min);
var max=Math.max.apply(null, array)
gs.print(max);

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022