MCPcopy Create free account
hub / github.com/CleanroomMC/ModularUI / argMax

Method argMax

src/main/java/com/cleanroommc/modularui/utils/DAM.java:134–143  ·  view source on GitHub ↗

Returns the index of the largest value in the array. If array is empty, -1 is returned. @param arr array @return index of largest value

(double[] arr)

Source from the content-addressed store, hash-verified

132 * @return index of largest value
133 */
134 public static int argMax(double[] arr) {
135 if (arr.length == 0) return -1;
136 if (arr.length == 1) return 0;
137 if (arr.length == 2) return arr[0] >= arr[1] ? 0 : 1;
138 int index = 0;
139 for (int i = 1; i < arr.length; i++) {
140 if (arr[i] > arr[index]) index = i;
141 }
142 return index;
143 }
144
145 /**
146 * Returns the index of the smallest value in the array. If array is empty, -1 is returned.

Callers 1

maxMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected