det matriz
by juvian
JavaScript
function Num(n){
this.isNumber;
this.symbol;
this.quantity=0;
this.isNumeric = function( obj ) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
this.isNumber=this.isNumeric(n);
if(this.isNumber){
this.quantity=n;
this.symbol=n;
}else{
if(n.split("").indexOf('(') != -1){
this.symbol=n;
}else{
this.symbol=n.split("").sort().join("");
}
}
}
function det(arr){
this.matrix=arr;
this.cMatrix=[];
var handler=this;
this.result={};
this.init=function(arr){
if(arr.length==0) return null;
if(!handler.isSquare(matrix)) return null;
handler.fillMatrix(arr);
handler.run(handler.cMatrix);
}
this.fillMatrix=function(matrix){
for(var i =0; i < matrix.length;i++){
handler.cMatrix.push([]);
for(var j=0;j<matrix[i].length;j++){
var g=new Num(matrix[i][j]);
if(!g.isNumber) g.quantity=1;
handler.cMatrix[i].push(g)
}
}
}
this.run=function(matrix, factor){
if(factor==undefined || factor == null) factor=new Num(1);
if(matrix.length==2){
var result1=handler.getResult(matrix[0][0], matrix[1][1], 1 );
var result2=handler.getResult(matrix[0][1], matrix[1][0], -1);
result1=handler.getResult(result1, factor,1);
result2=handler.getResult(result2, factor,1);
if(!handler.result.hasOwnProperty(result1.symbol)){
handler.result[result1.symbol]=result1;
}else{
handler.result[result1.symbol].quantity+=result1.quantity;
}
if(!handler.result.hasOwnProperty(result2.symbol)){
handler.result[result2.symbol]=result2;
}else{
handler.result[result2.symbol].quantity+=result2.quantity;
...