JSFiddle - React, Tailwind, and code Playground

by CommandLineDesign

JavaScript

function solution(S) {
    var timeLog = S.split('\n');
    var rate = 0;
    var resultTrack = [];
    for(var i = 0; i < timeLog.length; i++){
        resultTrack[i] = [];
        resultTrack[i].PhoneNumber = timeLog[i].split(',')[1];
		var callTime = timeLog[i].split(',')[0].split(':');
        var callTimeInSeconds = Number((callTime[0]*3600))+Number((callTime[1]*60))+Number(callTime[2]);
        rate = 3;
        resultTrack[i].callTimeInSeconds = callTimeInSeconds;
        console.log('seconds' + callTimeInSeconds);
        if(callTimeInSeconds >= 300){
        	rate = 150;    
        }
        var startedMinutes = Math.ceil((callTimeInSeconds/60));
        console.log('started Minutes' + startedMinutes);
       	console.log('price in dollars' + (startedMinutes*rate)/100);
        resultTrack[i].price = (startedMinutes*rate)/100;
        console.log(resultTrack);
    }
    var tmp =[];
    for(var i = 0; i < resultTrack.length; i++){
        var currentNumber = resultTrack[i].PhoneNumber
		console.log(currentNumber);
        console.log(tmp[currentNumber]);
    	if(tmp[currentNumber]){
        	tmp[currentNumber].count ++;
        } else {
            tmp[currentNumber] = [];
        	tmp[currentNumber].count = 1;
        }
    }
    var currentMax = 0
    var highestID = '';
    var tempKeys = Object.keys(tmp);
    for(var i = 0; i < tempKeys.length; i++){
    	currentCount = tmp[tempKeys[i]].count;
        if(currentCount > currentMax || 
           (currentCount = currentMax && Number(tempKeys[i].join('-')) < Number(highestID.join('-')))){
        	currentMax = currentCount;
            highestID =  tempKeys[i];
        }
    }
    console.log(highestID);
    var totalCost = 0;
    for(var i=0; i < resultTrack.length; i++){
    	if(resultTrack[i].PhoneNumber == highestID){
        	resultTrack[i].price = 0;
        }
        totalCost += resultTrack[i].price;
    }
    console.log(tempKeys);
    console.log(currentMax);
    return totalCost*100;
}

var...