Evaluate Highest/Lowest Variable

Hello.

I am trying to evaluate which of 4 variables have the lowest number. I have 4 variables, each of which represent the number of dead persons from a team. So for example:
Team A: 2 Dead


Team B: 3 Dead


Team C: 5 Dead


Team D: 9 Dead


These numbers can vary and I would like to be able to determine which team (variable) has the most amount of living persons. I can do that with the following code below. However, it is possible for 2+ teams to be tied with the least amount of living persons. For example:
Team A: 2 Dead


Team B: 2 Dead
Team C : 5 Dead
Team D: 9 Dead


What if 2, 3 or all 4 teams are tied with the lowest dead? I know one way to approach it. Check the values of each of the 4 variables and determine the lowest number. Then check each variable that matches that number and enable a respective switch.


So with the above example, it would identify 2 as the lowest number and turn on switches for Teams A and B. I'm not sure how to do that though. I googled that the javascript may be like:


Array.min = function( array ){
return Math.min.apply( Math, array );
};

Code:
var minimum = Array.min(array);


But I'm not certain how to adjust that appropriately for MV's variables. Can anyone help me or show me a simpler solution?

Code:
◆If:Total Dead (Now) = 0
  ◆Control Variables:#0395 Team Most = 0
  ◆Jump to Label:EXIT
  ◆
:End
◆If:Team A Dead Count < Team B Dead Count
  ◆If:Team A Dead Count < Team C Dead Count
    ◆If:Team A Dead Count < Team D Dead Count 
      ◆Control Variables:#0395 Team Most = 1
      ◆
    :End
    ◆
  :End
  ◆
:End
◆If:Team B Dead Count < Team A Dead Count
  ◆If:Team B Dead Count < Team C Dead Count
    ◆If:Team B Dead Count < Team D Dead Count 
      ◆Control Variables:#0395 Team Most = 2
      ◆
    :End
    ◆
  :End
  ◆
:End
◆If:Team C Dead Count < Team A Dead Count
  ◆If:Team C Dead Count < Team B Dead Count
    ◆If:Team C Dead Count < Team D Dead Count 
      ◆Control Variables:#0395 Team Most = 3
      ◆
    :End
    ◆
  :End
  ◆
:End
◆If:Team D Dead Count  < Team A Dead Count
  ◆If:Team D Dead Count  < Team B Dead Count
    ◆If:Team D Dead Count  < Team C Dead Count
      ◆Control Variables:#0395 Team Most = 4
      ◆
    :End
    ◆
  :End
  ◆
:End
◆Label:EXIT
I tried:


◆Control Variables:#0083 Team A Dead Count = 8
◆Control Variables:#0084 Team B Dead Count = 7
◆Control Variables:#0085 Team C Dead Count = 3
◆Control Variables:#0086 Team D Dead Count  = 3
◆Script:var tempArray = [$gameVariables.value(83), $gameVariables.value(84), $gameVariables.value(85), $gameVariables.value(86)];
:      :
:      :Array.min = function( array ){
:      :    return Math.min.apply( Math, array );
:      :};
:      :
:      :var minimum = Array.min(tempArray);
:      :
:      :$gameVariables.setValue(396, minimum);
◆Text:None, Window, Bottom
:    :Lowest: \V[396]

And it works!! Still though, if there's a more efficient way I'd like to know. Also, is there a way to randomly select a value from an array?
I would like to store various phrases in an array and randomly pull out one to be said.
If you'd like to try it yourself, Math.random() generates a random floating point number from 0 to 0.9999999999999.... and so on.


Arrays have indexes, indexes start at 0 and go up. For example:


var a = [etc values here...] 


a[Math.floor(Math.random()*a.length)] would give a random value in the array. This method works for all array lengths. If your array was named something else (ex. tempArray) you'd use tempArray[Math.floor(Math.random()*tempArray.length)].

Original thread: https://forums.rpgmakerweb.com/threads/evaluate-highest-lowest-variable.74111/