-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
100 lines (71 loc) · 2.35 KB
/
functions.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
function createMembers(numberOfMembers) {
addMember(i);
i += 1;
}
function addMember (index) {
const div = document.createElement('div');
const label = document.createElement('label');
label.textContent = 'Annual salary of member ' + index;
const input = document.createElement('input');
input.type = 'number'
input.className = 'salary';
div.appendChild(label)
div.appendChild(input)
$rowsManipulation.appendChild(div);
}
function removeDinamicallyAddedRows () {
const lastChild = $rowsManipulation.lastChild;
lastChild.remove();
i = i - 1;
}
function HTMLCollectionIntoArray (HTMLCollection) {
let array = [];
for (let i = 0; i < (HTMLCollection.length); i++) {
let item = Number(HTMLCollection.item(i).value)
if (HTMLCollection.item(i).value.length !== 0) {
array.push(item);
}
}
return array;
}
function getHighestAnnualSalary (array) {
const highest = Math.max.apply(Math, array);
return highest;
}
function getLowestAnnualSalary (array) {
const lowest = Math.min.apply(Math, array);
return lowest;
}
function getAverage (array) {
let arraySum = 0;
for (let i = 0; i < array.length; i++) {
let arrayItem = Number(array[i]);
arraySum += arrayItem;
}
average = Number((arraySum / array.length).toFixed(2));
return average;
}
function getMonthlyAverage (array) {
let monthlyArray = [];
for (let i = 0; i < array.length; i++) {
let arrayItem = Number(array[i]);
let monthlyArrayItem = arrayItem / 12;
monthlyArray.push(monthlyArrayItem);
}
let monthlyArraySum = 0;
for (let i = 0; i < monthlyArray.length;i++) {
let monthlyArrayItem = Number(monthlyArray[i]);
monthlyArraySum += monthlyArrayItem;
}
monthlyAverage = Number((monthlyArraySum / monthlyArray.length).toFixed(2));
return monthlyAverage;
}
function showResults (highest, lowest, average, monthlyAverage) {
document.getElementById('highest-annual-salary').value = highest;
document.getElementById('lowest-annual-salary').value = lowest;
document.getElementById('annual-salary-average').value = average;
document.getElementById('monthly-salary-average').value = monthlyAverage;
}
function clearDataForNewCalculation () {
annualSalaries = [];
}