-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
136 lines (114 loc) · 3.33 KB
/
index.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function quadratic(a, b, c) {
let discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
let root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
let root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
return `The roots are: [${root1}, ${root2}]`;
} else if (discriminant === 0) {
let root = -b / (2 * a);
return `The root is: [${root}]`;
} else {
let realPart = -b / (2 * a);
let imaginaryPart = Math.sqrt(-discriminant) / (2 * a);
return `The roots are: [{r: ${realPart}, i: ${imaginaryPart}}, {r: ${realPart}, i: ${-imaginaryPart}}]`;
}
}
function squareArea(side) {
return `The square area is: ${side * side}`;
}
function triangleArea(base, height) {
return `The triangle area is: ${(base * height) / 2}`;
}
function circleArea(radius) {
return `The circle area is: ${Math.PI * radius * radius}`;
}
function coneArea(radius, slantHeight) {
return `The cone area is: ${Math.PI * radius * (radius + slantHeight)}`;
}
function cylinderArea(radius, height) {
return `The cylinder area is: ${(2 * Math.PI * radius * height) + (2 * Math.PI * radius * radius)}`;
}
function fahrenheitToCelsius(fahrenheit) {
return `${fahrenheit} Fahrenheit in Celsius is: ${(fahrenheit - 32) * 5/9}`;
}
function celsiusToFahrenheit(celsius) {
return `${celsius} Celsius in Fahrenheit is: ${(celsius * 9/5) + 32}`;
}
function sin(x) {
return `Sin ${x} is: ${Math.sin(x)}`;
}
function cos(x) {
return `Cos ${x} is: ${Math.cos(x)}`;
}
function tan(x) {
return `Tan ${x} is: ${Math.tan(x)}`;
}
function log(x) {
return `Log ${x} is: ${Math.log(x)}`;
}
function ln(x) {
return `Ln ${x} is: ${Math.log(x)}`;
}
function exp(x) {
return `Exp ${x} is: ${Math.exp(x)}`;
}
function sqrt(x) {
return `Sqrt ${x} is: ${Math.sqrt(x)}`;
}
function degreesToRadians(x) {
return `${x} Degrees in Radians is: ${x * (Math.PI / 180)}`;
}
function radiansToDegrees(x) {
return `${x} Radians in Degrees is: ${x * (180 / Math.PI)}`;
}
function factorial(x) {
let f = 1;
for (let i = 2; i <= x; i++) {
f *= i;
}
return `The factorial of ${x} is: ${f}`;
}
function standardDeviation(arr) {
let sum = 0;
let mean;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
mean = sum / arr.length;
sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += (arr[i] - mean) ** 2;
}
return `The standard deviation is: ${Math.sqrt(sum / arr.length)}`;
}
function isPrime(n) {
if (n <= 1) {
return `${n} is not a Prime`;
}
for (let i = 2; i < n; i++) {
if (n % i === 0) {
return `${n} is not a Prime`;
}
}
return `${n} is a Prime`;
}
exports.standardDeviation = standardDeviation;
exports.isPrime = isPrime;
exports.sin = sin;
exports.cos = cos;
exports.tan = tan;
exports.log = log;
exports.ln = ln;
exports.exp = exp;
exports.sqrt = sqrt;
exports.degreesToRadians = degreesToRadians;
exports.radiansToDegrees = radiansToDegrees;
exports.factorial = factorial;
exports.celsiusToFahrenheit = celsiusToFahrenheit;
exports.fahrenheitToCelsius = fahrenheitToCelsius;
exports.cylinderArea = cylinderArea;
exports.coneArea = coneArea;
exports.circleArea = circleArea;
exports.triangleArea = triangleArea;
exports.squareArea = squareArea;
exports.quadratic = quadratic;