var summArr = [];
var datesArr = [];
$("#start-but").click(function(){
var summ = - (+$("#start-summ").val() - (+$("#start-firstPay").val()));
summArr = [summ];
datesArr = [new Date(+$("#start-date-year").val(), (+$("#start-date-mon").val()-1), +$("#start-date-day").val())];
makeTable(+$("#start-pays").val());
});
$("#fin").find("button").click(function(){
$("#fin").hide();
$("#start-form").show().find("input").val("");
});
var makeTable = function(c){
$("#start-form").hide();
var table = $("#pays").show().find("tbody").html("");
for (var i=0; i<c; i++){
addTr(table, i+1);
}
table.append("<tr><td colspan=3><button>Узнать ПСК</button></td></tr>");
table.find("button").click(countPsk);
}
var addTr = function(table, count){
table.append("<tr class='tr'><td>"+count+$("#tr").html());
}
var countPsk = function(){
var rows = $("#pays").find(".tr");
rows.each(function(){
summArr.push(+$(this).find("input").eq(3).val());
datesArr.push(getDateFromTr($(this)));
});
var psk = getPsk(summArr, datesArr);
$("#fin").show().find("span").html("ПСК = "+psk+" %");
$("#pays").hide();
}
var getDateFromTr = function(tr){
var y = +tr.find("input").eq(2).val();
var m = +tr.find("input").eq(1).val()-1;
var d = +tr.find("input").eq(0).val();
return new Date (y, m ,d);
}
/*model psk*/
var getCpb = function (bp){
return 365/bp;
}
var equation = function(summs, dates, bp, j){
var res = 0;
for (var i=0; i<summs.length; i++){
var datesDif = (dates[i]-dates[0])/(24*60*60*1000);
var q = Math.floor(datesDif/bp);
var e = ( (datesDif) % bp ) / bp;
res = res + summs[i] / ( (1 + e*j) * Math.pow(1+j, q) );
}
return Math.abs(res);
}
var getModa = function(arr){
var res = false, resCount = 0;
for (var i=0; i<arr.length; i++){
var checkItem = arr[i];
var checkItemCount = 0;
for (var j=0; j<arr.length; j++){
if (arr[j]==checkItem){
checkItemCount++;
}
}
if (checkItemCount>resCount){
res =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.