JavaScript Y combinator and Z combinatorNote that this topic is a sub-set of lambda calculus. First how to prove that Y combinator is a fixed-point combinator: Y f = (lg. (lx. g (x x)) (lx. g (x x))) f = (lx. f (x x)) (lx. f (x x)) = l(lx. f (x x)). f (x x) = f ((lx. f (x x)) (...Oct 25, 2022·1 min read
JavaScript RecursionProgramming using recursion is really simple yet intuitive. Here are a few examples in js. First, a factorial function (https://jsfiddle.net/ky8fjza7/). /* factorial: F(n) = n * F(n-1) F(n-1) = (n - 1) * F(n-2) ... F(1) = 1 */ // factorial functio...Oct 23, 2022·1 min read
JavaScript Using generator function for fibonacci sequenceHere's a nice use-case for generator functions. The following is an implementation of fibonacci sequence of arbitrary size (see https://jsfiddle.net/cj83gkno/). Generator function makes this really easy. /* Fibonacci sequence of arbitrary length 0, 1...Oct 21, 2022·2 min read
JavaScript Using generator functionConsider the following custom Iterator. function makeRangeIterator(start = 0, end = Infinity, step = 1) { let nextIndex = start; let iterationCount = 0; const rangeIterator = { next() { let result; if (nextIndex < end) { ...Oct 18, 2022·2 min read
JavaScript Difference between assignment and definitionIn this article I lay out how assignment is different from definition. const getMe={ __proto__: { get foobar() { return `${this.fb} is foobar!` }, set foobar(v) { this.fb...Oct 18, 2022·1 min read
JavaScript Using mixin to set up Event listenterslet eventMixin = { /** * Subscribe to event, usage: * menu.on('select', function(item) { ... } */ on(eventName, handler) { if (!this._eventHandlers) this._eventHandlers = {}; if (!this._eventHandlers[eventName]) { this._eve...Oct 17, 2022·1 min read
JavaScript How to set inheritance using new or Object.setPrototypeOfHere we are going to set inheritance rules without using class extends.... By using new operator First way is to use new operator. Whenever you instantiate an object using new operator, you are also creating an instance. // Constructor function C() {...Oct 13, 2022·2 min read