-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrays.js
141 lines (95 loc) · 2.2 KB
/
Arrays.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
const c = alert
const ci = console.log
let ar = ['Hola','Cielo',"Como","Estas"];
//c(ar[0]);
// Desestructuracion //
let[a1,a2,a3,a4]=ar; //igualamos valores en una linea
// Agregar y Quitar //
ar.push("Te quiero")//agregar
ar.pop(); //Quitar
ar.unshift("Nick Dice") //Agrega al inicio de la fila
ar.shift() //Elimina el primer elemento
//splice(locacion,cuantos elemntos elimiminamos,"agregar","ahregar"...)
ar.splice(1,0,"Bonita")
ar.slice(2,4); // No modifica el Array original
const revertText = string => string.split("").reverse().join("")
let ab = ["A","Z","Q","B","2","1"];
ab.sort() //Ordena de orden alfabetico
ab.sort().reverse()
let numbers=[2,5,8,4,7,8,0,1,8]
numbers.sort((a,b)=> a-b) //Algoritmo que pregunta quien es mayor
numbers.join(",") //separa de acuerdo a lo requerido
// Unir Arrays //
let num = [2,8,4,8,8,2,1,4,8,2,0,0,5145644,461]
numbers.concat(num)
// Encontrar Posicion //
num.indexOf(8)
num.find( num => num > 100) //primer valos mayor a 100
//5145644
//finidex lo mismo solo que esta vez muetra el indice
c(ar[2]);
//Eliminar Duplicados //
new Set(num)
const removeDuplicates = arr => [...new Set(arr)] //Remueve duplicados
/*
let num3=[2,5,4,8,7,8,10,1]
undefined
Math.min(num3)
NaN
Math.min(...num3)
1
*/
let arr = ["a","b","c","d"]
for(let i = 0; i <arr.length;i++)
{
ci(arr[i])
}
/*
let novia = ["Cielo","Camacho","Cornejo"]
undefined
for(let n of novia){
ci(n)
}
VM2609:2 Cielo
VM2609:2 Camacho
VM2609:2 Cornejo
novia.forEach((el,i) => {
ci(el)
ci(i)
})
VM3283:2 Cielo
VM3283:3 0
VM3283:2 Camacho
VM3283:3 1
VM3283:2 Cornejo
VM3283:3 2
let array = []
undefined
numbers.forEach(el => {
array.push(el*el)
})
//Busqueda //
some uno cumple
every todos cumplen
novia (3) ["Cielo", "Camacho", "Cornejo"]
novia.some(el => el ==="Cielo")
novia
(3) ["Cielo", "Camacho", "Cornejo"]
novia.every(el => el.length >= 4)
*/
/*num3
(8) [2, 5, 4, 8, 7, 8, 10, 1]
num3.map(e => e*e)
(8) [4, 25, 16, 64, 49, 64, 100, 1]
let e = num3.map(e => e*e)
undefined
e
(8) [4, 25, 16, 64, 49, 64, 100, 1]
//Filtra
num3.filter(e => e>5)
(4) [8, 7, 8, 10]
let suma= num3.reduce((a,b)=>a+b)
undefined
suma
45
*/