-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathchallenge.js
More file actions
92 lines (77 loc) · 1.72 KB
/
Copy pathchallenge.js
File metadata and controls
92 lines (77 loc) · 1.72 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
87
88
89
90
91
92
function crearArrayFrutas() {
const frutas = ['manzana', 'banana', 'naranja'];
return frutas;
}
function crearArrayMixto() {
const mixto = [1, 'texto', true, null, { tipo: 'objeto' }];
return mixto;
}
function obtenerPrimerElemento(array) {
return array[0];
}
function obtenerUltimoElemento(array) {
return array[array.length - 1];
}
function agregarAlFinal(array, elemento) {
array.push(elemento);
return array;
}
function agregarAlInicio(array, elemento) {
array.unshift(elemento);
return array;
}
function insertarEnPosicion(array, posicion, elemento) {
array.splice(posicion, 0, elemento);
return array;
}
function reemplazarEnPosicion(array, posicion, nuevoElemento) {
array.splice(posicion, 1, nuevoElemento);
return array;
}
function eliminarUltimo(array) {
array.pop();
return array;
}
function eliminarPrimero(array) {
array.shift();
return array;
}
function eliminarEnPosicion(array, posicion) {
array.splice(posicion, 1);
return array;
}
function obtenerLongitud(array) {
return array.length;
}
function esArray(valor) {
return Array.isArray(valor);
}
function encontrarIndice(array, elemento) {
return array.indexOf(elemento);
}
function crudCompleto() {
let numeros = [1, 2, 3];
numeros.unshift(0);
numeros.push(4);
numeros.splice(1, 1, 10);
numeros.pop();
numeros.splice(2, 1); // Eliminar el elemento 2 que quedó en la posición 2
return numeros;
}
module.exports = {
crearArrayFrutas,
crearArrayMixto,
obtenerPrimerElemento,
obtenerUltimoElemento,
agregarAlFinal,
agregarAlInicio,
insertarEnPosicion,
reemplazarEnPosicion,
eliminarUltimo,
eliminarPrimero,
eliminarEnPosicion,
obtenerLongitud,
esArray,
encontrarIndice,
crudCompleto,
};