eguatech/egua

Refatorar verificação de parâmetros

Closed this issue · 0 comments

egua/src/lib/eguamat.js

Lines 151 to 171 in 5671a03

module.exports.aprox = function(x,z) {
if (isNaN(x) || x === null)
throw new RuntimeError(
this.token,
"Você deve prover valores para aprox(x,z)."
);
if (z == undefined) { z = 2; }
console.log("type of = " + typeof (x));
if (typeof (x) == "number") { x = x.toFixed(z) }
else if (x[0].length == undefined) { // 1D array
for (var i = 0; i < x.length; i++) {
x[i] = parseFloat(x[i].toFixed(z));
}
} else
for (var i = 0; i < x.length; i++) { // 2D array
for (var j = 0; j < x[0].length; j++) {
x[i][j] = parseFloat(x[i][j].toFixed(z));
}
}
return x; //OK
};