Clase 7 Flashcards

1
Q

Retorno de función JS

A

function mayorQue($n){
return (m) => m > $n;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ejemplo de calculadora basada en rotorno de funciones JS

A

function calculadora(op){
if(op == “suma”){
return (a,b) => a+b;
}else{
return (a,b) => a*b;
}
}

let sumar = calculadora(‘suma’);
let multiplicar = calculadora(‘multiplicar’)

console.log(sumar(2,5))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Recibir funciones como parametro JS

A

function recorrerArray($arr,$fn){
$arr.forEach(element => {
$fn(element)
});
}

const array = [1,2,3,4]

recorrerArray(array,console.log)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Uso de arrow funciones JS

A

let mostrarTexto = (el)=>console.log(el*3)

recorrerArray(array, mostrarTexto)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly