# Iteration Error in Google Earth Engine?

The below code computes area elevation relationship by iteration algorithm. But when the interval sets to 0.5 shows same area values in a row(like the below picture).

``````Map.centerObject(geometry);

var dem = ee.Image("JAXA/ALOS/AW3D30/V2_2").clip(geometry).select('AVE_DSM');

var demMin = ee.Number(dem.reduceRegion(ee.Reducer.min(), geometry, 250).get('AVE_DSM')).float();
var demMax = ee.Number(dem.reduceRegion(ee.Reducer.mean(), geometry, 250).get('AVE_DSM')).float();

print('minElevation:',demMin);
print('maxElevation:',demMax);

//////////////////////////////// area elevation

var interval = ee.Number(0.5);

var waterlevel = ee.List.sequence(demMin,demMax,interval);

var calcArea = function(level,list){

var inundated = dem.lte(ee.Number(level));

var area = inundated.multiply(30.0).multiply(30.0);
var totalarea = area.reduceRegion(ee.Reducer.sum(), geometry);

};

var first = ee.List([]);

var AREA = ee.List(waterlevel.iterate(calcArea, first));

print('Area Estimated:',AREA)
``````

But when the interval sets to 0.5 shows same area values in a row(like the below picture).

The bands have integer values: if you `print(dem.bandTypes());` then you can see the type reported as `AVE_DSM: signed int16`. Therefore, any step smaller than 1.0 will sometimes not differ from the previous step. There simply isn't any more resolution in the data.

You didn't ask about performance, but a note: in general, `iterate` is not very efficient, and should be avoided whenever possible. In this case, there is no need at all to use `iterate` because each value computed does not depend on the previous value(s); `map` suffices. Here is your code modified to use `map`:

``````var calcArea = function(level) {
var inundated = dem.lte(ee.Number(level));
var area = inundated.multiply(30.0).multiply(30.0);
var totalarea = area.reduceRegion(ee.Reducer.sum(), geometry);