Commit 5761a27a authored by GoshaZotov's avatar GoshaZotov

modify functions: cPERCENTILE, cRANK, cRANK_AVG

parent d2b5f8d9
......@@ -2435,22 +2435,21 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
for(var i = 0; i < args.length; i++){
var arg = args[i];
if (cElementType.cellsRange === arg.type || cElementType.cellsRange3D === arg.type) {
if(typeArray && cElementType.array === typeArray[i]){
newArgs[i] = arg;
}else{
newArgs[i] = arg.cross(arg1);
//для массивов отдельная ветка
if(typeArray && cElementType.array === typeArray[i])
{
if (cElementType.cellsRange === arg.type || cElementType.array === arg.type) {
newArgs[i] = arg.getMatrix();
} else if (cElementType.cellsRange3D === arg.type) {
newArgs[i] = arg.getMatrix()[0];
} else {
newArgs[i] = new cError(cErrorType.not_available);
}
}else if (cElementType.cellsRange === arg.type || cElementType.cellsRange3D === arg.type) {
newArgs[i] = arg.cross(arg1);
}else if(cElementType.array === arg.type){
if(bAddFirstArrElem){
if(typeArray && cElementType.array === typeArray[i]){
newArgs[i] = [];
arg.foreach(function (elem) {
newArgs[i].push(elem);
});
}else{
newArgs[i] = arg.getElementRowCol(0,0);
}
newArgs[i] = arg.getElementRowCol(0,0);
}else{
indexArr = i;
newArgs[i] = arg;
......
......@@ -908,7 +908,7 @@
{
//sort array
aSortArray.sort (function sortArr(a, b) {
return a.value - b.value;
return a - b;
});
var nSize = aSortArray.length;
......@@ -917,7 +917,7 @@
if ( nSize == 0 /*|| nGlobalError != FormulaError::NONE*/ ){
res = null;
} else {
if ( fVal < aSortArray[ 0 ].value || fVal > aSortArray[ nSize - 1 ].value ){
if ( fVal < aSortArray[ 0 ] || fVal > aSortArray[ nSize - 1 ] ){
res = null;
}else{
var fLastPos = 0;
......@@ -925,12 +925,12 @@
var bFinished = false;
var i;
for ( i = 0; i < nSize && !bFinished /*&& nGlobalError == FormulaError::NONE*/; i++ ){
if ( aSortArray[ i ].value === fVal ){
if ( aSortArray[ i ] === fVal ){
if ( fFirstPos < 0 ){
fFirstPos = i + 1.0;
}
}else{
if ( aSortArray[ i ].value > fVal ){
if ( aSortArray[ i ] > fVal ){
fLastPos = i;
bFinished = true;
}
......@@ -5019,10 +5019,9 @@
cPERCENTILE.prototype.argumentsMax = 2;
cPERCENTILE.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cPERCENTILE.prototype.Calculate = function (arg) {
function percentile(argArray) {
function percentile(A, k) {
var tA = [], alpha = k.getValue();
var tA = [], A = argArray[0], alpha = argArray[1];
for (var i = 0; i < A.length; i++) {
for (var j = 0; j < A[i].length; j++) {
......@@ -5039,30 +5038,17 @@
return getPercentile(tA, alpha);
}
var arg0 = arg[0], arg1 = arg[1];
if (arg0 instanceof cArea || arg0 instanceof cArray) {
arg0 = arg0.getMatrix();
} else if (arg0 instanceof cArea3D) {
arg0 = arg0.getMatrix()[0];
} else {
return this.value = new cError(cErrorType.not_available);
}
if (arg1 instanceof cArea || arg1 instanceof cArea3D) {
arg1 = arg1.cross(arguments[1]);
} else if (arg1 instanceof cArray) {
arg1 = arg1.getElement(0);
}
var oArguments = this._prepareArguments(arg, arguments[1], true, [cElementType.array]);
var argClone = oArguments.args;
arg1 = arg1.tocNumber();
argClone[1] = argClone[1].tocNumber();
if (arg1 instanceof cError) {
return this.value = arg1;
var argError;
if (argError = this._checkErrorArg(argClone)) {
return this.value = argError;
}
return this.value = percentile(arg0, arg1);
return this.value = this._findArrayInNumberArguments(oArguments, percentile);
};
/**
......@@ -5575,26 +5561,33 @@
return this.value = argError;
}
var calcTDist = function(argArray){
var calcRank = function(argArray){
var number = argArray[0];
var ref = argArray[1];
var order = argArray[2];
if(!ref.length){
return new cError(cErrorType.wrong_value_type);
}
var changedRef = [];
for(var i = 0; i < ref.length; i++){
if(cElementType.number === ref[i].type){
changedRef.push(ref[i]);
for (var i = 0; i < ref.length; i++) {
for (var j = 0; j < ref[i].length; j++) {
if (ref[i][j] instanceof cError) {
return ref[i][j];
} else if (ref[i][j] instanceof cNumber) {
changedRef.push(ref[i][j].getValue());
} else if (ref[i][j] instanceof cBool) {
changedRef.push(ref[i][j].tocNumber().getValue());
}
}
}
if(!changedRef.length){
return new cError(cErrorType.wrong_value_type);
}
var res = rank(number, changedRef, order);
return null !== res && !isNaN(res) ? new cNumber(res) : new cError(cErrorType.wrong_value_type);
};
return this.value = this._findArrayInNumberArguments(oArguments, calcTDist);
return this.value = this._findArrayInNumberArguments(oArguments, calcRank);
};
/**
......@@ -5623,26 +5616,33 @@
return this.value = argError;
}
var calcTDist = function(argArray){
var calcRank = function(argArray){
var number = argArray[0];
var ref = argArray[1];
var order = argArray[2];
if(!ref.length){
return new cError(cErrorType.wrong_value_type);
}
var changedRef = [];
for(var i = 0; i < ref.length; i++){
if(cElementType.number === ref[i].type){
changedRef.push(ref[i]);
for (var i = 0; i < ref.length; i++) {
for (var j = 0; j < ref[i].length; j++) {
if (ref[i][j] instanceof cError) {
return ref[i][j];
} else if (ref[i][j] instanceof cNumber) {
changedRef.push(ref[i][j].getValue());
} else if (ref[i][j] instanceof cBool) {
changedRef.push(ref[i][j].tocNumber().getValue());
}
}
}
if(!changedRef.length){
return new cError(cErrorType.wrong_value_type);
}
var res = rank(number, changedRef, order, true);
return null !== res && !isNaN(res) ? new cNumber(res) : new cError(cErrorType.wrong_value_type);
};
return this.value = this._findArrayInNumberArguments(oArguments, calcTDist);
return this.value = this._findArrayInNumberArguments(oArguments, calcRank);
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment