getRangeArray method

ArrayComplex getRangeArray(
  1. int start,
  2. int end, {
  3. int step = 1,
  4. bool reverse = false,
})

Return an array given an index interval

  • start : start index close interval
  • end : end index open interval
  • step : optional, step between samples
  • reverse : optional, return a reversed array

Examples

var var list = ArrayComplex([
  Complex(real: 3.0, imaginary: 4.0),
  Complex(real: 3.0, imaginary: 4.0),
  Complex(real: 3.0, imaginary: 4.0)]);
var b = list.getRangeArray(0, 1);

print(b)

/* output:
ArrayComplex([
  Complex(real: 3.0, imaginary: 4.0)
]);
*/

Implementation

ArrayComplex getRangeArray(int start, int end,
    {int step = 1, bool reverse = false}) {
  var b = ArrayComplex.empty();
  for (var i = start; i < end; i += step) {
    b.add(this[i]);
  }

  if (reverse) {
    b = ArrayComplex(b.reversed.toList());
  }

  return b;
}