-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebtech_task.html
More file actions
40 lines (40 loc) · 1.57 KB
/
Copy pathwebtech_task.html
File metadata and controls
40 lines (40 loc) · 1.57 KB
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
<!DOCTYPE html><html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Коэффициент корреляции</title>
</head>
<body>
<h4>472043</h4>
<script>
const urladress = window.location.href.split('?')[0];
const params = location.href.split('?')[1];
const paramArray = params.split('&');
let A = [], B = [];
for (const param of paramArray) {
const [key, value] = param.split('=');
if (key === 'A') {
A = value.split(',').map(Number);
} else if (key === 'B') {
B = value.split(',').map(Number);
}
}
function pearsonCorrelation(x, y) {
const n = x.length;
if (n === 0) return 0;
const sumX = x.reduce((a, b) => a + b, 0);
const sumY = y.reduce((a, b) => a + b, 0);
const sumX2 = x.reduce((a, b) => a + (b * b), 0);
const sumY2 = y.reduce((a, b) => a + (b * b), 0);
const sumXY = x.reduce((total, xi, i) => total + (xi * y[i]), 0);
const numerator = (n * sumXY) - (sumX * sumY);
const denominator = Math.sqrt((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY));
if (denominator === 0) return 0;
return numerator / denominator;
}
const correlationCoeff = pearsonCorrelation(A, B);
const result = Math.abs(correlationCoeff).toFixed(3);
document.title = result;
</script>
</body>
</html>