There is an array of calls for calls "is a string with the date and number of seconds spoken." The first 100 (one hundred) minutes per day are evaluated at 1 coin per minute; After 100 minutes in one day, each minute costs 2 coins per minute; All calls are rounded to the nearest minute. For example, 59 s ≈ 1 min, 61 s ≈ 2 min;
I have the answer in the end 502 and should be 106
var calls = ["2014-02-05 60", "2014-02-05 60", "2014-02-05 60", "2014-02-05 6000"],///ответ должен быть 106 data = [], limit = 100, price = 0, priceOfDay = 0, thatDayDuration = 0, minutes, thatDayMinutes, duration, price; calls.forEach(function(e){ var tmp = e.split(" "); data.push({'date' : tmp[0], 'duration' : tmp[1]}); }) data.forEach(function(el1,idx1){ var out = false; data.forEach(function(el2,idx2){ if(el1.date==el2.date && idx1!=idx2){ out = true; thatDayMinutes = Math.ceil(el2.duration/60); } }) if(out){ thatDayDuration += thatDayMinutes; thatDayMinutes = (thatDayDuration > 100) ? ((thatDayDuration - 100)*2)+100 : thatDayDuration; priceOfDay = thatDayMinutes; }else{ duration = Math.ceil(el1.duration/60); minutes = (duration > 100) ? (duration-100)*2+100 : duration; price += minutes; } total = price + priceOfDay; }) console.log(total)