{"size": 7729, "ext": "js", "max_stars_repo_path": "script.js", "max_stars_repo_name": "aa3447/Calculator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "script.js", "max_issues_repo_name": "aa3447/Calculator", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script.js", "max_forks_repo_name": "aa3447/Calculator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.0299145299, "max_line_length": 174, "alphanum_fraction": 0.3374304567}
"use strict";
function shunting(i){
        var input = i.split("");
        var output = [];
        var stack = []; 
        var prev = "";
        var localInput = "";
        while(input.length > 0){
              localInput = input.splice(0,1)[0];
            if($.isNumeric(localInput) || localInput === "."){// checks for numbers or decimals
                while($.isNumeric(input.slice(0,1)[0] ) ||  input.slice(0,1)[0]=== "."){//if found loop till you don't find one
                    localInput += input.splice(0,1)[0];   
               } 
             output.push(localInput);
            }
            else if(localInput === "^" || localInput === "R" ){//power , right assoctive precdence 4
                while( stack[0] === "-u"){
                output.push(stack.splice(0,1)[0]);
                }
                stack.unshift(localInput);  
            }
            else if(localInput ===  "/" || localInput ===  "*"){//left assocative. precadence 3
                 while( stack[0] === "/" || stack[0] === "*"  || stack[0] === "-u" ||  stack[0]  === "^" || stack[0]  === "R"){
                        output.push(stack.splice(0,1)[0]);
                 
                 }
                  stack.unshift(localInput);
             }
             else if( localInput ===  "-"){
                if ((output === 0 || !($.isNumeric(prev))) && prev !== ")"  ){//uninay minus, right assoctive precdence 5
                    stack.unshift("-u");
                }else{//infix minus,left assoctaive. preadence 2
                     while( stack[0] ===  "-" || stack[0] ===  "+" || stack[0] === "/" || stack[0] === "*" || stack[0] === "-u" ||  stack[0]  === "^" ||  stack[0]  === "R"){
                        output.push(stack.splice(0,1)[0]);
                    }
                 stack.unshift(localInput);
                }
            }
            
            else if( localInput === "+"  ){//left assoctaive. preadence 2
                    while( stack[0] ===  "-" || stack[0] ===  "+" || stack[0] === "/" || stack[0] === "*"  || stack[0] === "-u" || stack[0] === "^" || stack[0]  === "R" ){
                        output.push(stack.splice(0,1)[0]);
                    }
                 stack.unshift(localInput);
             }
              
        
             else if(localInput === "("){
                 stack.unshift(localInput);
                 
             }
            else if(localInput === ")"){
                while( stack[0] !==  "(" && stack.length > 0){   
                    output.push(stack.splice(0,1)[0]);
                    
                }
                if(stack[0] === "("){
                    stack.splice(0,1);  
                }
                else{
                    output = "Missing Parenthesis";
                    return "Missing Parenthesis";
                }                
             }
            else{
                output = "Invalid Input";
                return "Invalid Input";
            }
            prev = localInput;
        }  
    
        while( stack.length > 0){
            if(stack[0] === "(" || stack[0] === ")"){
                output = "Missing Parenthesis";
                return "Missing Parenthesis";
            }
            output.push(stack.splice(0,1)[0]) 
        } 
        return output; 
    } 
  
function adder(i){//accepts arrays
    if(!(Array.isArray(i))){
        return i;
    }
    var a = 0;
    var b = 0;
    var stack = [];
    var diviser = 1;
    while(i.length  > 0 ){
        var localInput = i.splice(0,1)[0];
        if($.isNumeric(localInput)){//if number 
            localInput = Number(localInput);
            stack.unshift(localInput);
        }
        else if(localInput === "-u"){
           stack[0] = -1*stack[0];
        }
        else{
            if(stack.length >= 2){
                 a = stack.splice(0,1)[0];
                 b = stack.splice(0,1)[0]; 
                if(localInput === "+"){
                    a = a+b;
                }
                else if(localInput === "-"){
                    a = b-a;
                }
                else if(localInput === "*"){
                    a = a*b;
                }
                else if(localInput === "/"){
                    if(a === 0){
                     stack = "Can't divide by 0!";
                    return stack;
                    }
                    diviser = a;
                    a = b/a;
                }
                else if(localInput === "^"){
                    if(b < 0 && a < 1){
                        if(diviser%2 === 0){
                            stack = "No negative even roots!";
                            return stack;
                        }
                        else{
                            b = -1*b;
                            a = Math.pow(b,a);
                            a= -1*a;
                        }
                    
                    }else{
                         a = Math.pow(b,a);
                    }
                  
                }
              else if(localInput === "R"){
                if(b < 0){
                stack = "No negative bases!";
                return stack;
                }
                if(a < 0 && b%2 !== 0){
                    a = -1*a;
                    a = Math.pow(a,1/b);
                    a= -1*a;
                }
                else if(a < 0 && b%2 === 0){
                    stack = "No negative even roots!";
                    return stack;
                }
                else{
                  a = Math.pow(a,1/b);
                }
            }
            }
            else{
              stack = "Not enough numbers";
            return stack;
            }

            stack.unshift(a);
        }

    }
    if(stack.length > 1){
        stack = "Too many numbers";
        return stack;
    }
    else{
    return stack;
    }
}

$(function() {
    var input = "";
    var prev = "";
    var answer = "";
    var shunt = [];
    $("#form").keypress(function(e){
        if(e.which === 13){
            input = $("#input").val();
            prev = input;
            shunt = shunting(input);
            input = adder(shunt).toString();
            answer = input; 
            prev = prev + " = " + input;
            $("#prev").val(prev); 
            $("#input").val(input);
        }
    });
    $(".simple").click(function(){
        input = $("#input").val();
        input += $(this).text();
        $("#input").val(input);
    
    });
    $("#root").click(function(){
        input = $("#input").val(); 
        input += "R";
        $("#input").val(input);
    });
     $("#prevAnswer").click(function(){
         input = $("#input").val(); 
        input += answer;
        $("#input").val(input);
    });
    $("#clear").click(function(){
        input = "";
        $("#input").val(input);
    });
     $("#clearPrev").click(function(){
        prev = "";
        $("#prev").val(prev);
    });
     $("#delete").click(function(){
        input = $("#input").val();
        var temp = input.split("");
        temp[temp.length-1] = "";
        input = temp.join("");
        $("#input").val(input);
    });
     $("#equals").click(function(){
        input = $("#input").val();
        prev = input;
        shunt = shunting(input);
        input = adder(shunt).toString();
        answer = input; 
        prev = prev + " = " + input;
        $("#prev").val(prev);
        $("#input").val(input);
    });
 });
   
