-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
116 lines (106 loc) · 2.68 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
let sample = {
assertion: 0,
integer: 1,
"linked comprehension": 2,
"linked comprehension multiple choice": 0,
matrix: 1,
"matrix single choice": 0,
"multiple choice": 2,
"single choice": 2,
"subjective numerical": 0,
"true-false": 0
};
let total = 36;
// console.log(sample);
function rationDiff(updatedAlotment, sample, balance, item) {
console.log(
"rationDiff",
updatedAlotment,
sample,
balance,
item,
balance <= 0
);
const update = updatedAlotment + sample;
if (sample > balance) {
console.log("rationDiff", updatedAlotment + balance);
return updatedAlotment + balance;
} else {
return updatedAlotment + sample;
}
}
function ratiocalculate(sample, total) {
let notnegative = true;
let negativeChecked = false;
function rationBal(balance, alot, samplealot, item) {
updatedBal = balance - samplealot;
console.log(
"rationBal",
{ updatedBal },
{ balance },
{ alot },
{ samplealot },
{ item }
);
// console.log("rationBal", updatedBal < 0);
if (updatedBal <= 0) {
console.log(updatedBal, balance - (samplealot % 1));
return { updatedBal: alot - (balance - (samplealot % 1)), break: true };
} else {
return { updatedBal, break: false };
}
// return {
// updatedBal
// };
}
let length = Object.keys(sample).length;
let keys = Object.keys(sample);
let balanceTotal = total;
let updatedSample = {};
// let totalbalance = total;
// console.log("before balanceTotal", balanceTotal);
i = 0;
do {
// console.log(i, balanceTotal, notnegative);
// updatedSample[keys[i]] = updatedSample[keys[i]] > 0;
// if (notnegative) {
negativeChecked = true;
let updated;
// console.log({ balanceTotal });
for (j = 0; j <= length - 1; j++) {
updatedSample[keys[j]] =
updatedSample[keys[j]] > 0
? rationDiff(
updatedSample[keys[j]],
sample[keys[j]],
balanceTotal,
keys[j]
)
: sample[keys[j]];
updated = rationBal(
balanceTotal,
updatedSample[keys[j]],
sample[keys[j]],
keys[j]
);
balanceTotal = updated.updatedBal;
console.log("balanceTotal", updated);
if (balanceTotal <= 0 || updated.break) {
// console.log("asdasd", rationBal(balanceTotal, updatedSample[keys[j]]));
break;
}
}
if (updated.break) {
break;
}
// }
i++;
} while (i <= balanceTotal);
// for (i = 0; i <= balanceTotal; i++) {}
console.log(updatedSample, balanceTotal);
return {
balance: balanceTotal,
sample
};
}
ratiocalculate(sample, total);