Skip to content

Instantly share code, notes, and snippets.

@fernastereo
Created April 2, 2021 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernastereo/a065824d678cb4434a754c130301cc11 to your computer and use it in GitHub Desktop.
Save fernastereo/a065824d678cb4434a754c130301cc11 to your computer and use it in GitHub Desktop.
//Ejercicio 1
const count = (str, char) => {
console.log(`Recibidos ${str} y ${char}`);
let result = 0;
for (let index = 0; index < str.length; index++) {
if (char == str[index]) {
result++;
}
}
return result;
}
console.log(count('Hellolllll', 'l'));
//Ejercicio 2
const filter = (arr) => {
console.log(`Recibido ${arr}`);
//Manualmente
let result = [];
arr.forEach(element => {
if (element > 10) {
result.push(element);
}
});
return result;
//con Array.filter
// return arr.filter((elem) => elem > 10);
}
const data = [3, 12, 45, 7];
console.log(filter(data));
//Ejercicio 3
const hypotenuse = (a, b) => {
//Manualmente
const result = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
//Con la funcion hypot de JS
// const result = Math.hypot(a, b);
return result;
}
console.log(hypotenuse(10, 13));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment