JSFiddle - React, Tailwind, and code Playground

by shryme

HTML

<textarea id="txt">
</textarea>
<br>
<button onclick="run()">
run
</button>
<br>

<pre id="lbl"></pre>

<pre id="lblA"></pre>
<pre id="lblB"></pre>

CSS

textarea { resize:vertical; min-height:300px; min-width:500px; }

JavaScript

function run() {
    var txt = document.getElementById('txt').value;

    var arr = txt.split('\n');
    arr = arr.filter(function(n) {
        return n != ""
    });

    var list = new Array();

    for (var i = 0; i < arr.length; i++) {
        var cur = arr[i];
        var ip = cur.substr(1, cur.indexOf(']') - 1);
        var time = cur.substr(cur.indexOf('for ') + 3, cur.indexOf('(') - cur.indexOf('for ') - 4);
        var cash = cur.substr(cur.indexOf('earned ') + 7, cur.indexOf('euros') - cur.indexOf('earned ') - 8);

        var t = time.split(":");
        var d = new Date();
        d.setHours(t[0]);
        d.setMinutes(t[1]);

        var n = Number(t[1]) / 60;

        var hours = Number(t[0]) + n;


        var obj = {
            ip: ip,
            time: hours,
            cash: Number(cash),
            ratio: Number(cash) / hours,
        };

        list.push(obj);


    }


    function compare(a, b) {
        if (a.ratio < b.ratio)
            return 1;
        else if (a.ratio > b.ratio)
            return -1;
        else
            return 0;
    }

    list.sort(compare);
    console.log(list);
    
    var lbl = document.getElementById('lbl');
    var lblA = document.getElementById('lblA');
    var lblB = document.getElementById('lblB');

    var str = "";
    var strA = "";
    var strB = "";
    for (var i = 0; i < list.length; i++) {
    	str += list[i].ip + " - " + list[i].ratio + "\n";
      strA += list[i].ip + "\n";
      strB += list[i].ratio + "\n";
    }
    

    lbl.innerText = str;
    lblA.innerText = strA;
    lblB.innerText = strB.replace(/\./g, ',');
    


}