-
Notifications
You must be signed in to change notification settings - Fork 6
/
math.js
89 lines (68 loc) · 1.69 KB
/
math.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
console.group('Cuadrado')
const ladoCuadrado = 5;
const perimetroCuadrado = ladoCuadrado * 4;
const areaCuadrado = ladoCuadrado * ladoCuadrado;
console.log({
ladoCuadrado,
perimetroCuadrado,
areaCuadrado,
});
function calcularCuadrado(lado) {
return {
perimetro: lado * 4,
area: lado * lado,
};
}
console.groupEnd('Cuadrado')
console.group('Triangulo')
const ladoTriangulo1 = 6;
const ladoTriangulo2 = 6;
const ladoTrianguloBase = 4;
const alturaTriangulo = 5.5;
const perimetroTriangulo = ladoTriangulo1 + ladoTriangulo2 + ladoTrianguloBase;
const areaTriangulo = (ladoTrianguloBase * alturaTriangulo) / 2;
function calcularTriangulo(lado1, lado2, base, altura) {
return {
perimetro: lado1 + lado2 + base,
area: (base * altura) / 2,
};
}
function calcularAlturaTriangulo(lado1, base) {
if (lado1 == base) {
console.warn('Este no es un triángulo isosceles');
} else {
// h = raizcuadrada(lado1**2 - (b**2)/4)
return Math.sqrt( (lado1 ** 2) - ( (base ** 2) ) / 4 );
}
}
console.log({
ladoTriangulo1,
ladoTriangulo2,
ladoTrianguloBase,
alturaTriangulo,
perimetroTriangulo,
areaTriangulo,
});
console.groupEnd('Triangulo')
console.group('Circle')
const radioCirculo = 3;
const diametroCirculo = radioCirculo * 2;
const PI = 3.1415;
const circunferencia = diametroCirculo * PI;
const areaCirculo = (radioCirculo ** 2) * PI;
console.log({
radioCirculo,
diametroCirculo,
PI,
circunferencia,
areaCirculo,
});
function calcularCirculo(radio) {
const diametro = radio * 2;
const radioAlCuadrado = Math.pow(radio, 2);
return {
circunferencia: diametro * Math.PI,
area: radioAlCuadrado * Math.PI,
};
}
console.groupEnd('Circle')