From f6718afb32b5502e0b1a32dffdfbc4c0a20e2f8b Mon Sep 17 00:00:00 2001 From: Kilokem Date: Fri, 20 Sep 2024 19:02:49 +0200 Subject: [PATCH] IHadEnaugh --- FunctionalFun/script.js | 53 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/FunctionalFun/script.js b/FunctionalFun/script.js index 2427cb2..172d0df 100644 --- a/FunctionalFun/script.js +++ b/FunctionalFun/script.js @@ -46,4 +46,55 @@ document.addEventListener("DOMContentLoaded", function(){ } }); -//https://youtu.be/lfmg-EJ8gm4?si=78bU7V4mL7MVoYw_&t=14391 \ No newline at end of file +//https://youtu.be/lfmg-EJ8gm4?si=78bU7V4mL7MVoYw_&t=14391 + + +//Callback functions!!! + +function sum(callback, a, b) { + let suma = a + b; + callback(suma); +} + +function summa(b, a) { + return b + a +} + +function displaynum(num) { + console.log("The number: ", num); +} + +function displaytxt(num) { + console.log("The Text: ", num); +} + +sum(displaynum, 5, 8); +sum(displaytxt, "alma", "fa"); +sum(console.log, 5, 7 ) + + +let numberok = [1, 2, 3, 4, 5] + +numberok.forEach(displaynum) //!!! .forEach() METHOD!!!!!! + + +let numbbb = numberok.map(doubler); //map() +console.log(numbbb); +function doubler(params) { + return params**2; +} + + + + +let nummb = numberok.filter(ifeven) //filterer() +console.log(nummb); +function ifeven(n){ + return n % 2 === 0; +} + +let total = numberok.reduce(summa) //reduce() +console.log(total) + + +//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=17107 \ No newline at end of file