diff --git a/app/functions.js b/app/functions.js index 07fa74590..881c6165f 100644 --- a/app/functions.js +++ b/app/functions.js @@ -35,5 +35,9 @@ exports.functionsAnswers = { curryIt: function(fn) { + }, + + yCombinator: function (fn) { + } }; diff --git a/tests/app/functions.js b/tests/app/functions.js index ee5b9bd07..ae7f611f9 100644 --- a/tests/app/functions.js +++ b/tests/app/functions.js @@ -142,4 +142,20 @@ describe('functions', function() { expect(typeof result).to.eql('number'); expect(result).to.eql(curryMe(a, b, c)); }); + + it('you should be able to create y-combinator function for self-recurring fibonacci function', function () { + var result, yFibonacci; + + function fibonacci(n, self) { + return n < 1 ? 0 : (n <= 2 + ? 1 + : self(n - 2, self) + self(n - 1, self)); + } + + yFibonacci = functionsAnswers.yCombinator(fibonacci); + result = yFibonacci(8); + + expect(typeof result).to.eql('number'); + expect(result).to.eql(21); + }); });