compareobject method

  1. @Deprecated('Use `compare` instead.')
List compareobject(
  1. List list,
  2. String operations,
  3. dynamic object
)

compare values inside an array with given object and operations. function will return a new boolen array

var arr = [[1,1,1],[2,2,2],[3,3,3]];
var compare = m2d.compare(arr,'>',2);
print(compare);
//[[false, false, false], [false, false, false], [true, true, true]]

Implementation

@Deprecated('Use `compare` instead.')
List compareobject(List list, String operations, object) {
  var shapee = shape(list);
  var operatns = ['>', '<', '>=', '<=', '==', '!='];
  if (!_checkArray(list)) throw new Exception('Uneven array dimension');
  if (!operatns.contains(operations))
    throw new Exception('Current operation is not support');
  if (shapee.length < 2)
    throw new Exception(
        'Currently support 2D operations or put that values inside a list of list');
  var res = fill(shapee[0], shapee[1], true);
  for (var i = 0; i < shapee[0]; i++) {
    for (var j = 0; j < shapee[1]; j++) {
      try {
        var val = list[i][j];
        if (operations == operatns[0]) {
          if (val > object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        } else if (operations == operatns[1]) {
          if (val < object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        } else if (operations == operatns[2]) {
          if (val >= object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        } else if (operations == operatns[3]) {
          if (val <= object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        } else if (operations == operatns[4]) {
          if (val == object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        } else {
          if (val != object) {
            res[i][j] = true;
          } else {
            res[i][j] = false;
          }
        }
      } catch (e) {
        throw new Exception(
            'Sorry can\'t compare string with number (Not javascript)');
      }
    }
  }
  return res;
}