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
| // Copy-paste this into a JavaScript console to execute. | |
| probabilities = ( | |
| [ | |
| [1], | |
| [2], | |
| [3], | |
| [4], | |
| [5], | |
| [6], | |
| [7], |
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 fib( | |
| numberOfIterations | |
| ) { | |
| let numbers = [] | |
| let currentNumber = 1 | |
| let previousNumber = 0 | |
| for ( | |
| let currentIteration = 1 | |
| ;currentIteration <= numberOfIterations |
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
| const performanceTest = (func, iterations) => { | |
| const before = performance.now() | |
| for(let i = 0; i < iterations; i++) { | |
| func() | |
| } | |
| const after = performance.now() | |
| const elapsed = after - before | |
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
| const connectToServerEpic = ( | |
| action$, | |
| ) => ( | |
| action$ | |
| .pipe( | |
| ofType(CONNECT_TO_SERVER), | |
| switchMap(({ | |
| reconnectionTimeout, | |
| // ... | |
| }) => ( |
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
| webSocketConnection$ | |
| .pipe( | |
| // ... | |
| map(receivedWebSocketMessage), | |
| // ... | |
| ) |
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
| const connectToServerEpic = ( | |
| action$, | |
| ) => ( | |
| action$ | |
| .pipe( | |
| ofType(CONNECT_TO_SERVER), | |
| switchMap(({ | |
| // ... | |
| }) => ( | |
| action$ |
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
| webSocketConnection | |
| .pipe( | |
| // ... | |
| startWith( | |
| connectionReady( | |
| webSocketConnection$, | |
| ) | |
| ), | |
| ) |
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
| webSocketConnection | |
| .pipe( | |
| // ... | |
| catchError(() => ( | |
| timer( | |
| reconnectionTimeout, | |
| ) | |
| .pipe( | |
| // ... | |
| mapTo(reconnectToServer()), |
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
| const WebSocket = require('ws') | |
| const { webSocket } = require('rxjs/webSocket') | |
| const createWebSocketConnection = ({ | |
| protocol, | |
| url, | |
| }) => ( | |
| webSocket({ | |
| protocol, | |
| url, |
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
| const WebSocket = require('ws') | |
| const { webSocket } = require('rxjs/webSocket') | |
| const webSocketConnection$ = ( | |
| webSocket({ | |
| protocol: 'v1', | |
| url: 'http://example.com:3000', | |
| WebSocketCtor: WebSocket, | |
| }) | |
| ) |
NewerOlder