Buenas de nuevo! Envio mi solucion al reto de la seccion 4, pueden comentar alguna mejora o duda
// Challenge Section #4
// * Activity #1
const genericList = [];
// * Activity #2
const programmingLanguages = [`JavaScript`, `C`, `C++`, `Kotlin`, `Python`];
// * Activity #3
programmingLanguages.push(`Java`);
programmingLanguages.push(`Ruby`);
programmingLanguages.push(`GoLang`);
// * Activity #4
const showElements = function (arr) {
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
};
showElements(programmingLanguages);
// * Activity #5
const showElementsReverse = function (arr) {
for (let i = arr.length - 1; i >= 0; i--) {
console.log(arr[i]);
}
};
showElementsReverse(programmingLanguages);
// * Activity #6
const prom = function (arr) {
let result = 0;
for (let i = 0; i < arr.length; i++) {
result += arr[i] / arr.length;
}
return result.toFixed(1);
};
console.log(prom([10, 9, 8, 10, 9]));
// * Activity #7
const showMaxAndMin = function (arr) {
let max = arr[0];
let min = arr[0];
for (let i = 0; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}
if (min > arr[i]) {
min = arr[i];
}
}
console.log(`Max number: ${max} and Min number: ${min}`);
};
showMaxAndMin([3, 4, 7, 1, 23]);
// * Activity #8
const sumElements = function (arr) {
let result = 0;
for (let i = 0; i < arr.length; i++) {
result += arr[i];
}
return result;
};
console.log(sumElements([10, 15, 20]));
// * Activity #9
const findNumber = function (arr, el) {
for (let i = 0; i < arr.length; i++) {
if (el === arr[i]) {
return i;
}
}
return -1;
};
console.log(findNumber([4, 3, 8, 16, 20], 7));
// * Activity #10
const sumTwoArr = function (arr1, arr2) {
const resultArr = [];
for (let i = 0; i < arr1.length; i++) {
resultArr[i] = arr1[i] + arr2[i];
}
return resultArr;
};
console.log(sumTwoArr([1, 2, 3], [1, 2, 3]));
// * Activity #11
const sqrArr = function (arr) {
const resultArr = [];
for (let i = 0; i < arr.length; i++) {
resultArr.push(arr[i] * arr[i]);
}
return resultArr;
};
console.log(sqrArr([2, 5, 10]));