Hi,
once again a rather simple question the reference isn't telling. How can I get the max value of an array.
public var myarray = [10, 20, 30, 40, 50, 60];
var maximum = max.steps; //didn't work
Regards Marcus
Hi,
once again a rather simple question the reference isn't telling. How can I get the max value of an array.
Regards Marcus
What is max.steps? Where is max coming from and what is step?
I don't think Monkey C has a built-in function that does that, but you can easily write one yourself.
e.g.
// returns null for an empty array
function arrayMax(a) {
var a_size = a.size();
if (a_size == 0) {
return null;
}
var max = a[0];
for (var i = 1; i < a_size; i++) {
if (max < a[i]) {
max = a[i];
}
}
return max;
}Ahh ok that's what I wanted to know.
I helped myself with a while construction but hoped there was a cleaner version.
do {
if(steps[counter]>biggest){
biggest=steps[counter];
}
counter++;
}
while (counter < steps.size());