• 0

Closures, currying, partially applied function interview question in javascript

Write a function say which logs the following.

console.log( say('Foo')('bar')() ) // => "Foo bar "

console.log( say('Hi')('my')('name')('is')('Foo')() ) // "Hi my name is Foo "

Understanding closures, currying, partially applied functions in javascript is pre-requisite before seeing the solution. I would recommend reading that article first.

Note: Solution does not use recursion. There is a difference between recursion and function returning a function.