DEV Community

Discussion on: Functional programming basics part 2: Higher order function

Collapse
 
ysael profile image
ysael pepin • Edited

Hi Alvaro,

thanks :)

let's say we want to create a greeter function that will take a greeting copy but we know that this copy will change depending on the context.

we can do:


const greeter = copy  => {
    return name => `${name} ${copy}`
}

const politeGreeter = greeter('you are very welcome here')
const weirdGreeter = greeter('you look weird today!')

console.log(politeGreeter('Ysael')) // Ysael you are very welcome here
console.log(weirdGreeter('Ysael')) // Ysael you look weird today!

witch will allow us to make different greeter functions.

Hope that helps :)