From 09da3a8d7bb8b0fa2496df883c9f9fc2c124dc14 Mon Sep 17 00:00:00 2001
From: Andrej Rasevic <andrej@rasevicengineering.com>
Date: Tue, 14 Jan 2025 08:47:48 -0500
Subject: [PATCH] adding callback example

---
 LectureCodeExamples/Week2/Callback.js | 45 +++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 LectureCodeExamples/Week2/Callback.js

diff --git a/LectureCodeExamples/Week2/Callback.js b/LectureCodeExamples/Week2/Callback.js
new file mode 100644
index 0000000..5119bcc
--- /dev/null
+++ b/LectureCodeExamples/Week2/Callback.js
@@ -0,0 +1,45 @@
+// Function Declaration
+
+function printName(name, cb) {
+    console.log("Inside the printName function")
+    console.log(name)
+    cb(name)
+}
+
+
+// function expression
+let printReverseName = function(name) {
+    console.log(name.split("").reverse().join(""))
+}
+
+
+// arrow function
+let returnReverseString = str => {
+   return str.split("").reverse().join("")
+}
+
+printName("Nikola", printReverseName)
+
+console.log(returnReverseString("THis is reversing a string"))
+
+let sports = ["rowing", "cycling", "tennis", "padel", "soccer"]
+
+let newSports = sports.map(sport => {
+    console.log("this is a multiline function")
+    return returnReverseString(sport)
+})
+
+console.log(sports)
+console.log(newSports)
+
+let shortSports = sports.filter(sport => sport.length <= 5)
+let longerSports = sports.filter((sport) => sport.length > 5)
+console.log(shortSports)
+console.log(longerSports)
+
+let initial = 0
+let sum = sports.reduce((sum, sport) => {
+    return sum + sport.length
+}, initial)
+
+console.log(`The sum of all the lengths in the sports array is ${sum}`)
\ No newline at end of file
-- 
GitLab