You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//1 - Crea ejemplos de funciones básicas que representen las diferentes posibilidades del lenguaje:
2
+
3
+
// funsion simple -------------------------------
4
+
// Autoejecutable
5
+
(function(){
6
+
console.log("Autoejecutable");
7
+
})();
8
+
//declarativa
9
+
functionhello(){
10
+
console.log('hello word , funcion declarativa')
11
+
}
12
+
13
+
14
+
// Expresión (anónimas)
15
+
constsumFunction=function(a,b){
16
+
returna+b
17
+
}
18
+
19
+
20
+
21
+
// Flecha (arrow)
22
+
constarrowFunction=(a,b)=>{
23
+
returna*b
24
+
}
25
+
26
+
27
+
// con retorno ------------------------------------
28
+
29
+
functionsquare(number){
30
+
returnnumber*number;
31
+
}
32
+
// este return puedo grardarlo en una variable
33
+
letarea=square(4)
34
+
35
+
36
+
// con argumento -----------------------------------
37
+
functionnombre(nombre){
38
+
console.log('mi nombre es '+nombre)
39
+
}
40
+
41
+
42
+
43
+
functionidioma(idioma,nombre){
44
+
console.log(idioma+nombre)
45
+
}
46
+
47
+
48
+
49
+
// argumento default
50
+
51
+
functiondefaultsuma(a=5,b=2){
52
+
returna*b
53
+
}
54
+
55
+
56
+
57
+
//Callbacks
58
+
varfunB=function(){
59
+
returnconsole.log('Funcion B ejecutada');
60
+
};
61
+
varfunA=function(callback){
62
+
callback();
63
+
};
64
+
65
+
66
+
//2 - Comprueba si puedes crear funciones dentro de funciones.
67
+
//Sucesión de Fibonacci complegidad 2^n
68
+
69
+
functionfibonacci(num){
70
+
if(num<2)returnnum
71
+
//funciona en 0 y 1 retorna num , cuando el numero es mayor , va retrocediendo hasta llegar al 1al llegar al 1 entra en el if y es por eso que se puede parar la recursividad
72
+
73
+
returnfibonacci(num-2)+fibonacci(num-1)
74
+
}
75
+
76
+
console.log(fibonacci(10))
77
+
78
+
//3- Pon a prueba el concepto de variable LOCAL y GLOBAL.
0 commit comments