public void cleanData(double lower, double upper) {
// screw iterating backwards so i'm using another array
ArrayList<Double> cleaned = new ArrayList<>();
for (double temperature : temperatures) {
if (temperature >= lower && temperature <= upper) {
// add in same order
cleaned.add(temperature);
}
}
// simply overwrite old array, no removing.
temperatures = cleaned;
}
b)
public int longestHeatWave(double threshold)
{
// default is 0, i lazy
int duration, max;
for (double temperature : temperatures) {
// for every temperature checked that is greater than the threshold, the length of the wave increases by one
if (temperature > threshold) {
duration++;
if (duration > max) {
// set new max if reached
max = duration;
}
}
// reset duration to 0
else {
duration = 0;
}
}
return max;
}
Comments
You are seeing this because your Disqus shortname is not properly set. To configure Disqus, you should edit your
_config.yml
to include either adisqus.shortname
variable.If you do not wish to use Disqus, override the
comments.html
partial for this theme.