A collection of links to the excellent "Composing Software" series of medium stories by Eric Elliott.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Primitive Type Comparison | |
| var a = 1; | |
| var b = 1; | |
| var c = a; | |
| console.log(a == b); //true | |
| console.log(a === b); //true | |
| console.log(a == c); //true | |
| console.log(a === c); //true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // write code for this function: sum(a)(b)(c)....( n)(). This should return the sum of a+b+c....+n. | |
| let sum = function(a) { | |
| return function(b) { | |
| if (b) { | |
| return sum(a + b) | |
| } | |
| return a; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function throttle(callback, wait) { | |
| let flag = true; | |
| return function() { | |
| let context = this, args = arguments; | |
| if (flag) { | |
| callback.apply(context, args); | |
| flag = false; | |
| } | |
| setTimeout(() => { | |
| flag = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function.prototype.myBind = function(...args) { | |
| let context = this; | |
| let params = args.slice(1); | |
| return function(...args2) { | |
| context.apply(args[0], [...params, ...args2]) | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function debounce(func, wait = 100) { | |
| let timeout; | |
| return function(...args) { | |
| clearTimeout(timeout); | |
| timeout = setTimeout(() => { | |
| func.apply(this, args); | |
| }, wait); | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint-disable */ | |
| // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
| if (window) { | |
| window.requestAnimFrame = (function(){ | |
| return window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| function(callback) { | |
| window.setTimeout(callback, 1000 / 60); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Test</title> | |
| <link rel="manifest" href="manifest.json"> | |
| </head> | |
| <body> | |
| <p> | |
| If the <code>beforeinstallprompt</code> event fires, there will be a button displayed allowing | |
| you to use <code>prompt()</code> on the deferred event. | |
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if user scrolling down | |
| if user scrolled at bottom most isfilterAtBottom: (pageYOffset > positionFilterTopWhenFilterAtBottomMost) | |
| then set position top gridProductsContainerHeight - gridFixedFilterContainerHeight | |
| else | |
| if user has reached bottom of filter container (pageYOffset > gridFixedFilterContainerBottom) | |
| then set position fixed and style accordingly | |
| set wasScrollingDownwards true | |
| ser wasScrollingUpwards false | |
| else user has not yet reached bottom AND wasScrollingUpwards earlier | |
| then set position relative and calculate top. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| showMoreFilterPositionTop = ( | |
| searchFilterPositionTop, | |
| gridFiltersContainerRect, | |
| ) => { | |
| const defaultHeaderHeight = 120; | |
| const filterTitleHeight = 60; | |
| const showMoreFilterPositionTop = | |
| Math.abs( | |
| searchFilterPositionTop - gridFiltersContainerRect.top |