Skip to content
Snippets Groups Projects
Commit 09da3a8d authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

adding callback example

parent 90ef25fc
No related branches found
No related tags found
No related merge requests found
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment