/* Advanced Number Handler Algorithm - Made by Thomas | Distribution, selling or usage of this program is prohibited

                          !!! READ FIRST !!!

Notations that work: (A = Coeficent, B = Exponent, {e, E, E[0-2]} = Notation)
AeB -> Basic Scientific notation | 1e10
1eAEB (E[0]) -> Modified Scientific notaion, Basic ^ 10 | 1e1E10 -> 1e(10^10 )
1e1EAE[1]B -> Modified T1 Scientific notation, Modifed ^ 10 | 1e1E1E[1]10 -> 1e(10^10^10)

E[x] represents the ID of the notation starting at 0 (NOT including regular e) 
E[0] is not required but will still work the same as a single CAPITOL E

                          ~~~~~ IPUTS ~~~~~
                            
When you input to 'number' use the simplified format
only use 1 E. Examples
1e10, 1E10 or 1E[0]10, 1E[1]10, 1E[2]10 */

var number = '1e3003' // MUST BE A STRING (in qutations) | follow format above
var Req, Coef, Expn, Type, q, TypeIndex, p
var Tier = 0, AmntE = 0
var Subtract = undefined

console.log("Original Number: " + number)

if (number.includes('E[2]')) { 
    Tier = 4;
    Expn = number.split('E[2]')[1];
    console.log(number);
} else if (number.includes('E[1]')) { 
    Tier = 3;
    Expn = number.split('E[1]')[1];
} else if (number.includes('E[0]') || number.includes('E')) { 
    Tier = 2;
    if (number.includes('E[0]')) { 
        Expn = number.split('E[0]')[1];
    } else {
        Expn = number.split('E')[1];
    }
} else if (number.includes('e')) {
    Tier = 1;
    Expn = number.split('e')[1];
    console.log(Expn)
} else {
    console.log('Number too large');
}
console.log(Tier + " Tier")

// make if statements where if it goes beyond the limit it will scale for the user

var Suffix = [] // where the number suffix is stored

var Requirements = [ // minimum number of expn needed to fit that index
    [3, 12, 33, 303, 3003], // a#1
    [60, 300, 3000], // a#2
    [69, 90, 600, 6000, 15000, 300000], // a#3
    [12, 90, 300, 3000] // a#2
];

var Types = [ // searches the sign befor the number, removes it, converts to num, and does the action related to it
    ['-3', '-3', '-30', '-300', '/1000'],
    ['-30', '-300', '/300'],
    ['-6', '-30', '-300', '-3000', '-15000', '/10'],
    ['-3', '-30', '-300', '-6000']
];

var SetsArray = [
      ["ERROR"], // idk
      ["", "Me", "Due", "Tre", "Te", "Pt", "He", "Hp", "Oct", "En"], // Tier 2
]

var FirstArray = [ // var p represents the 1 of 5 number,  
  ["k", "M", "B"], 
  ["", "U", "D", "T", "Qd", "Qn", "Sx", "Sp", "Oc", "No"],
  ["", "De", "Vt", "Tg", "qg", "Qg", "sg", "Sg", "Og", "Ng"],
  ["", "Ce", "Du", "Tr", "Qa", "Qi", "Se", "Si", "Ot", "Ni"],
  ["", "Mi", "Mc", "Na", "Pi", "Fm", "At", "Zp", "Yc", "Xo", 
   "Ve", "Me", "Due", "Tre", "Te", "Pt", "He", "Hp", "Oct", "En"]
];

var SecondArray = [
  ["", "Ic", "Tra", "TetC"],
  ["", "Hct", "Ki", "Mg", "Gg", "Ter", "Pet", "Ex", "Zet", "Yot",
   "Xen", "Dak", "Hen", "Dok", "Trad", "Ted", "Ped", "Exd", "Zed",
   "Yoda", "Ned", "Iki", "Ike", "Ict"],
  ["", "Ict", "Icp"]
];

var ThirdArray = [
  ["Icz", "Icx"], // 1e..EX -> x+1 *= 1000000 | STARTS at E69
  ["", "Trak", "Tek", "Pek", "Exa", "Zak", "Yok", "Nek", "Hot"], // 1e..EX -> En-1 + UNKNOWN | STARTS at E120
  ["", "Bot", "Tro", "Tot", "Pot", "Exo", "Zot", "Yoot", "Not", "Kal"], // 1e..EX -> En-1 + 300 | STARTS at E600
  ["", "Dal", "Tra"], // 1e..EX -> En-1 + 3000 | STARTS at E6000
  ["", "Pal", "Dak"], // 1e..EX -> En-1 + 150000 | STARTS at E15000
  ["", "Hota", "Mej", "Dake", "Hote", "Gj"] // 1e..E..E[1]X -> E[1]n-1 + 1 | STARTS at E300000 (E[1]5)
];

var FourthArray = [
  ["", "Ast", "Lun", "Ferm", "Jov", "Sol", "Bet", "Glo", "Gax",
   "Sup", "Vers", "Mult", "Vers", "Mult", "Pyr", "Gunt", "Kent",
   "Onl", "Pap", "Hous"], // 1e..E..E[1]X -> E[1]n-1 + 3 | STARTS at E[1]12
  ["", "Tron", "Bat", "Hand", "Ferm"], // 1e..E..E[1]X -> E[1]n-1 + 30 | STARTS at E[1]90
  ["", "Hut", "Mut"], // 1e..E..E[1]X -> E[1]n-1 + 300| STARTS at E[1]300
  ["", "Hep", "Bent"] // Array[1] -> E[1]3000, Array[2] -> E[2]9
];

console.log(`-------------------------`)

// work on dividing to get the index values

shortMain(Tier);

function shortMain(x) { // shortning the number automated
    for (let i = 0; i < Requirements[x - 1].length; i++) {
        q = Requirements[x - 1][i]
        if (Expn >= q) {
            p = i
        } 
    }
    shortType(p) 
    IndexNum = Requirements[x-1][p]
    ShortenTypePart1(Subtract, x, p, Expn)
    
}

function shortType(z) { // y is ... , z is [i]
    TypeIndex = Types[Tier - 1][z]
    if (TypeIndex.includes('-')) {
        Subtract = true
        TypeIndex = TypeIndex.replace('-', '')
        TypeIndex = Number.parseInt(TypeIndex)
    } else if (TypeIndex.includes('/')) {
        Subtract = false
        TypeIndex = TypeIndex.replace('/', '')
        TypeIndex = Number.parseInt(TypeIndex)
    } else {
        console.log("Error with finding sign")
    }
}

function ShortenTypePart1(f, g, h, Exp) {
    console.log(f,g,h,Exp)
    if (f === true) {
        while (Exp >= Requirements[g-1][h]) {
            Exp -= IndexNum
            AmntE++;
            FindTierEnd()
        }     
    } else if (f === false) {
        while (Exp >= Requirements[g-1][h]) {
            Exp /= TypeIndex
            AmntE++;
       }  
    } else {
        console.log("Error with finding sign") 
    } 
    FindTierEnd() 
}


//console.log(Exp)
console.log("1" + Suffix[0])

function FindTierEnd() {
    if (Tier == 1) {
        Suffix.push(FirstArray[p][AmntE])
    } else if (Tier == 2) {
        Suffix.push(SecondArray[p][AmntE])
    } else if (Tier == 3) {
        Suffix.push(ThirdArray[p][AmntE])
    } else if (Tier == 4) {
        Suffix.push(FourthArray[p][AmntE])
    } else {
        console.log("Unknwon TIER Error")
    }
}



//* E[2] = E[1] ^ 10 * 2
//more soon

/* NOTES FOR ME
new E format : 10^10^7 = E7#2 2 = number of 10s

==== array for multi var array ====

var module = {
    1: { req: 2, x: 3 }
};

console.log(module[1].x); 

*/

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: