text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/3.38/esri/copyright.txt for details.
  //>>built
  define("esri/arcade/featureset/support/stats","require exports ../../languageUtils ./shared ./sqlUtils ../../polyfill/promiseUtils".split(" "),function(z,g,y,q,r,n){function p(c){for(var a=0,b=0;b<c.length;b++)a+=c[b];return a/c.length}function t(c){for(var a=p(c),b=0,d=0;d<c.length;d++)b+=Math.pow(a-c[d],2);return b/c.length}function u(c){for(var a=p(c),b=0,d=0;d<c.length;d++)b+=Math.pow(a-c[d],2);return b/(c.length-1)}function v(c){for(var a=0,b=0;b<c.length;b++)a+=c[b];return a}function k(c,a,
  b,d){void 0===d&&(d=!1);try{var e=c.iterator(b);return n.create(function(f,h){w(e,[],a,d,f,h)})}catch(f){return n.reject(f)}}function w(c,a,b,d,e,f){y.tick(c.next().then(function(h){try{if(null!==h){var l=b.calculateValue(h);null===l?!1===d&&(a[a.length]=l):a[a.length]=l;return w(c,a,b,d,e,f)}e(a)}catch(m){f(m)}},f))}function x(c,a,b,d,e){return c.next().then(function(f){return null!==f?(f=d.calculateValue(f),void 0!==f&&null!==f&&void 0===a[f]&&(b.push(f),a[f]=1),b.length>=e&&-1!==e?b:x(c,a,b,d,
  e)):b})}Object.defineProperty(g,"__esModule",{value:!0});g.distinct=g.count=g.sum=g.stdev=g.variance=g.mean=g.max=g.min=g.calculateStat=g.decodeStatType=void 0;g.decodeStatType=function(c){switch(c.toLowerCase()){case "distinct":return"distinct";case "avg":case "mean":return"avg";case "min":return"min";case "sum":return"sum";case "max":return"max";case "stdev":case "stddev":return"stddev";case "var":case "variance":return"var";case "count":return"count"}return""};g.calculateStat=function(c,a,b){void 0===
  b&&(b=1E3);switch(c.toLowerCase()){case "distinct":a:{c=b;b=[];for(var d={},e=[],f=0;f<a.length;f++){if(void 0!==a[f]&&null!==a[f]){var h=a[f];if(q.isNumber(h)||q.isString(h))void 0===d[h]&&(b.push(h),d[h]=1);else{for(var l=!1,m=0;m<e.length;m++)!0===q.equalityTest(e[m],h)&&(l=!0);!1===l&&(e.push(h),b.push(h))}}if(b.length>=c&&-1!==c){a=b;break a}}a=b}return a;case "avg":case "mean":return p(a);case "min":return Math.min.apply(Math,a);case "sum":return v(a);case "max":return Math.max.apply(Math,a);
  case "stdev":case "stddev":return Math.sqrt(t(a));case "var":case "variance":return t(a);case "count":return a.length}return 0};g.min=function(c,a,b){return k(c,a,b,!0).then(function(d){return 0===d.length?null:Math.min.apply(Math,d)})};g.max=function(c,a,b){return k(c,a,b,!0).then(function(d){return 0===d.length?null:Math.max.apply(Math,d)})};g.mean=function(c,a,b){var d="";!1===r.isSingleField(a)&&(d=r.predictType(a,c.fields,null));return k(c,a,b,!0).then(function(e){if(0===e.length)return null;
  e=p(e);return null===e?e:"integer"===d?(e=+e,e=isFinite(e)?e-e%1||(0>e?-0:0===e?e:0):e,e):e})};g.variance=function(c,a,b){return k(c,a,b,!0).then(function(d){return 0===d.length?null:u(d)})};g.stdev=function(c,a,b){return k(c,a,b,!0).then(function(d){return 0===d.length?null:Math.sqrt(u(d))})};g.sum=function(c,a,b){return k(c,a,b,!0).then(function(d){return 0===d.length?null:v(d)})};g.count=function(c,a){try{return c.iterator(a).count()}catch(b){return n.reject(b)}};g.distinct=function(c,a,b,d){void 0===
  b&&(b=1E3);void 0===d&&(d=null);try{var e=c.iterator(d);var f=x(e,{},[],a,b)}catch(h){f=n.reject(h)}return f}});