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 opinionSort(items = []) { | |
| if (items.length === 0) { | |
| return []; | |
| } | |
| let left = []; | |
| let right = []; | |
| const pivot = items[0]; | |
| for (let i=1, l=items.length; i<l; i++) { | |
| const isLessThanPivot= window.confirm(`Confirm if you like ${pivot} more |
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
| // A simple, insecure hashing function | |
| function hashCode(value){ | |
| // Include the year in the hash function so the output will | |
| // change every Christmas | |
| value+= new Date().getFullYear(); | |
| let hash = 0; | |
| if (value.length == 0) return hash; | |
| for (i = 0; i < value.length; i++) { | |
| char = value.charCodeAt(i); |
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
| <main> | |
| <p id="result"></p> | |
| </main> | |
| <script> | |
| var testRoot = document.querySelector('main'); | |
| var result = document.querySelector('#result'); | |
| function addMessage(text) { | |
| var el = document.createElement('p'); | |
| el.textContent = text; |
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 combineFunctions(fn1, fn2, context) { | |
| context = context || null; | |
| return function() { | |
| var args = toArray(arguments); | |
| fn1.apply(context, args); | |
| return fn2.apply(context, args); | |
| } | |
| } |
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
| /** | |
| * @module GlobalEventListener | |
| */ | |
| (function(MutationObserver, exports) { | |
| 'use strict'; | |
| var proto = GlobalEventListener.prototype; | |
| /** | |
| * @this GlobalEventListener |
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
| /* | |
| * The problem: | |
| * Imagine you are on a long business trip with many connecting | |
| * flights. You have a handful of tickets - each with an origin city | |
| * and a destination - but the tickets are not in order. This algorithm | |
| * sorts the tickets chronologically, starting with your home city and | |
| * ending with your final destination. See bottom for an example. | |
| */ | |
| /* |
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
| /** | |
| * @desc A type-aware wrapper around window.localStorage | |
| * @module Store | |
| */ | |
| (function(exports) { | |
| 'use strict'; | |
| var proto = Store.prototype; | |
| /* Name of the properties that store type annotations. These |
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
| // Test object featuring a variety of basic data types | |
| var person = { | |
| name: 'Jim', | |
| age: 30, | |
| city: 'Chicago', | |
| favoriteFoods: [ | |
| { | |
| name: 'Pizza', | |
| cost: 5 | |
| }, |
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
| interface StoreOptions { | |
| /* The configuration object passed to the constructor of Store. | |
| This is where you specify the application's initial state | |
| along with reducers, pure functions that handle actions. */ | |
| state: StoreState; | |
| reducers: Array<StoreReducer>; | |
| } | |
| interface StoreAction { | |
| /* Actions are object literals that basically express how the application |
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
| interface BackoffConfig { | |
| // How many times a process can be retried before it fails permanently | |
| attempts?: number; | |
| // How long a process can run per attempt | |
| timeout?: number; | |
| // Pause between attempts | |
| delay?: number; | |
| // Controls how quickly the delay will increase with each attempt | |
| backoffExponent?: number; | |
| // For a good explanation of decorrelated jitter, see: |