#1-------------------------------------------------------------------------------- let listaGenerica[];
#2-------------------------------------------------------------------------------- let lenguagesDeProgramacion = ['JavaScript', 'C', 'C++', 'Kotlin','Python'];
#3-------------------------------------------------------------------------------- lenguagesDeProgramacion.push('Java', 'Ruby', 'GoLang');
#4-------------------------------------------------------------------------------- lista = lenguagesDeProgramacion;
function mostrarLista(lenguagesDeProgramacion){
console.log("Elementos de la lista: lenguagesDeProgramacion");
lista.forEach((elemento, index) => console.log(${index + 1}: ${elemento}
));
}
mostrarLista(lista);
#5--------------------------------------------------------------------------------
function mostrarListaInversa(lista){
console.log("Elementos de la lista en orden inverso: lenguagesDeProgramacion");
lista.slice().reverse().forEach((elemento, index) => console.log(${index + 1}: ${elemento}
));
}
mostrarListaInversa(lista);
#6.-------------------------------------------------------------------------------- let notas = [10, 9, 8, 8, 9, 10, 5, 8, 9, 10];
function calcularPromedio(notas) { if (!Array.isArray(notas) || notas.length === 0) { console.error("Error: Debes proporcionar una lista válida con al menos un elemento."); return 0; } const totalSumaNotas = notas.reduce((acc, num) => acc + num, 0); return totalSumaNotas / notas.length; }
console.log("Promedio:", calcularPromedio(notas));
#7.-------------------------------------------------------------------------------- let numeros = [10, 89, 78, 98, 59, 13, 55, 28, 87, 100];
function buscarMayorYMenor(numeros){
const mayor = Math.max(...numeros);
const menor = Math.min(...numeros);
console.log(El mayor es: ${mayor} y el menor es ${menor}
);
}
buscarMayorYMenor(numeros);
#8.-------------------------------------------------------------------------------- let numeros = [10, 89, 78, 98, 59, 13, 55, 28, 87, 100];
function sumarNumeros(numeros){
const totalSumaNumeros = numeros.reduce((acc, num) => acc + num, 0);
console.log(La suma total de la lista: ${numeros} es: ${totalSumaNumeros}
);}
sumarNumeros(numeros)
#9.-------------------------------------------------------------------------------- let listado = [10, 89, 78, 98, 59, 13, 55, 28, 87, 100]; let elemento = 4;
function buscarElemento(listado, elemento) { if (posicion >= 0 && posicion < listado.length) { return listado[posicion]; } else { return "Posición fuera de rango."; } }
buscarElemento(listado, elemento);
#10.-------------------------------------------------------------------------------- let list1 = [10, 89, 78, 98, 59]; let list2 = [13, 55, 28, 87, 100];
function sumarListas(lista1, lista2) { if (lista1.length !== lista2.length) { throw new Error("Las listas deben tener el mismo tamaño"); } return lista1.map((num, index) => num + lista2[index]); }
sumarListas(list1, list2);
#11.-------------------------------------------------------------------------------- let lista = [2, 3, 5, 7, 9];
function calcularCuadrados(lista) { return lista.map(num => num ** 2); }
calcularCuadrados(lista);