So, assuming your array is ordered as you shown, and "1-a1" means "group 1, number, index 1" (and "1-a4" means "group 1, number, "index 4" and "2-b1" means "group 2, number, index 1" and so on); and assuming that all the parts could be more than one number (like "11-8812" aka "group 11, a number like 88 and an index like 12"); you could have something like:
var array = ["1-81","1-102","1-93","1-24","2-881","2-122","2-13","2-984","3-2121","3-12","3-93","4-41","4-22"]
var max = {};
var group = "", count = 0;
for (var i = 0; i < array.length; i++) {
var parts = array[i].split("-");
if (group !== parts[0]) {
group = parts[0];
count = 0;
}
count++;
var number = +parts[1].replace(new RegExp(count + "$"), "");
max[group] = Math.max(max[group] || 0, number)
}
console.log(max)
You can also use an array instead of an object for max
. The whole procedure could be simplified if the last number is always one character.