THE FORUM IS IN READ-ONLY MODE
Find max number in array
-
How can i find max number in output varible array like this :
I know it will use javascript but i dont know how to write it after googlingexpires_at (List) = [1566570628, 1581845473, 1592991016, 1579196405, 1555680612, 1557845715, 1552642238, 1528765326, 1534758221, 1550223054, 1589880628, 1560591018, 1515352129, 1520470933, 1540028380, 1568915102, 1581942921, 1518051845, 1587288633, 1563629750, 1601124916, 1571477470, 1573742410, 1545389073, 1523408539, 1590237903, 1505140195, 1563355836, 1576767903, 1542802034, 1595755823, 1532012538, 1537436533, 1593186912, 1560777639, 1526000587, 1571505003, 1584444605, 1566379826, 1576315872, 1584437414, 1598520609]
Output will be : 1601124916
Thank you so much
-
To start from the end of the array,
<expires_at[-1]>
-
@Ruri said in Find max number in array:
To start from the end of the array,
<expires_at[-1]>
Sorry bro but i want to find max number in output varible array
i dont want to start from the end of the arrayThanks
-
you could use javascript Math.max() method
Example:BEGIN SCRIPT JAVASCRIPT a = Math.max(1,5,2); END SCRIPT -> VARS "a"
Result:
Jumping to line 5 DEBUG LOG: Parsing 1 variables SET VARIABLE a WITH VALUE 5 Completion value: 5
or if loliscript is faster assign first array index to a variable and iterate over array then check if current array index value is bigger than your variable if yes overwrite your variable with the array index value
but i think javascript wont make a big difference i would use that three liner
-
@Itamai
javascript Math.max() working bro . My output array has many number and i dont know how to add all the number to math.max because i dont know how many number in the out put so i cant do like this
a = Math.max(expires_at[0], expires_at[1], ... expires_at[n]);
-> ( working but i dont know how many (n) number)i try :
a = Math.max(expires_at[*]);But it not work. Please help
thank broexpires_at (List) = [1566570628, 1581845473, 1592991016, 1579196405, 1555680612, 1557845715, 1552642238, 1528765326, 1534758221, 1550223054, 1589880628, 1560591018, 1515352129, 1520470933, 1540028380, 1568915102, 1581942921, 1518051845, 1587288633, 1563629750, 1601124916, 1571477470, 1573742410, 1545389073, 1523408539, 1590237903, 1505140195, 1563355836, 1576767903, 1542802034, 1595755823, 1532012538, 1537436533, 1593186912, 1560777639, 1526000587, 1571505003, 1584444605, 1566379826, 1576315872, 1584437414, 1598520609]
-
@shinning119
replace the name "array" with your list variable nameBEGIN SCRIPT JAVASCRIPT a = Math.max.apply(null,array); END SCRIPT -> VARS "a"
Example i used:
PARSE " 1566570628, 1581845473, 1592991016, 1579196405, 1555680612, 1557845715, 1552642238, 1528765326, 1534758221, 1550223054, 1589880628, 1560591018, 1515352129, 1520470933, 1540028380, 1568915102, 1581942921, 1518051845, 1587288633, 1563629750, 1601124916, 1571477470, 1573742410, 1545389073, 1523408539, 1590237903, 1505140195, 1563355836, 1576767903, 1542802034, 1595755823, 1532012538, 1537436533, 1593186912, 1560777639, 1526000587, 1571505003, 1584444605, 1566379826, 1576315872, 1584437414, 1598520609" LR " " "," Recursive=TRUE -> VAR "array" BEGIN SCRIPT JAVASCRIPT a = Math.max.apply(null,array); END SCRIPT -> VARS "a"
Output:
<--- Executing Block PARSE ---> Parsed variable | Name: array | Value: [1566570628, 1581845473, 1592991016, 1579196405, 1555680612, 1557845715, 1552642238, 1528765326, 1534758221, 1550223054, 1589880628, 1560591018, 1515352129, 1520470933, 1540028380, 1568915102, 1581942921, 1518051845, 1587288633, 1563629750, 1601124916, 1571477470, 1573742410, 1545389073, 1523408539, 1590237903, 1505140195, 1563355836, 1576767903, 1542802034, 1595755823, 1532012538, 1537436533, 1593186912, 1560777639, 1526000587, 1571505003, 1584444605, 1566379826, 1576315872, 1584437414] Jumping to line 5 DEBUG LOG: Parsing 1 variables SET VARIABLE a WITH VALUE 1601124916 Completion value: 1601124916 Execution completed in 0.0869153 seconds
-
@Itamai
It work very well
thank bro so much