-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (72 loc) · 1.87 KB
/
index.js
File metadata and controls
88 lines (72 loc) · 1.87 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
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
let Formulas = {};
Formulas.add = function (a, b) {
return a + b;
}
Formulas.divideMultiply = function (a, b) {
if (b == 0) {
return undefined;
}
return a * a / b;
}
Formulas.roundNumbers = function (a) {
return Math.round(a);
}
Formulas.sinTimesCos = function (a) {
return Math.sin(a) * Math.cos(a);
}
Formulas.parseNumberFromString = function (a) {
return parseFloat(a);
}
Formulas.findObjectValueByKey = function (obj, key) {
let i;
let j;
let p;
for (i = 0; i < Object.keys(obj).length; i++) {
if (Object.keys(obj)[i] === key) {
return Object.values(obj)[i];
}
if (typeof Object.values(obj)[i] === "object" && (Object.values(obj)[i] !== null)) {
var newObject = Object.values(obj)[i];
for (j = 0; j < Object.keys(newObject).length; j++) {
if (Object.keys(newObject)[j] === key) {
return Object.values(newObject)[j];
}
if (typeof Object.values(newObject)[j] === "object" && (Object.values(newObject)[j] !== null)) {
var newObject2 = Object.values(newObject)[j];
for (p = 0; p < Object.keys(newObject2).length; p++) {
if (Object.keys(newObject2)[p] === key) {
return Object.values(newObject2)[p];
}
}
}
}
}
}
}
Formulas.parseJSON = function (a) {
return JSON.parse(a);
}
Formulas.pushToArray = function (a, b) {
return a.push(b);
}
Formulas.squareArrayValues = function (a) {
var newArr = a;
for (var i = 0; i < newArr.length; i++) {
newArr[i] = newArr[i] * newArr[i];
}
return a;
}
Formulas.sortArray = function (a) {
return a.sort(Formulas.sortNumbers)
}
Formulas.sortNumbers = function (a, b) {
return a - b;
}
Formulas.reverseString = function (a) {
var newString = "";
for (var i = a.length - 1; i >= 0; i--) {
newString += a[i];
}
return newString;
}
module.exports = Formulas;