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
| let startTime = -1; | |
| let animationDuration = 2000; | |
| function draw(timestamp) { | |
| let progress = 0; | |
| if (startTime < 0) { | |
| startTime = timestamp; | |
| } else { | |
| progress = timestamp - startTime; |
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
| let sun = new Image(); | |
| let moon = new Image(); | |
| let earth = new Image(); | |
| let canvas = document.getElementById('canvas'); | |
| let ctx = canvas.getContext('2d'); | |
| let config = { | |
| earth: { | |
| x: 150, |
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
| let drawPending = false; | |
| function redraw() { | |
| drawPending = false; | |
| // do drawing | |
| } | |
| function requestRedraw() { | |
| if (!drawPending) { |
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
| for (var name in map) { | |
| if (map.hasOwnProperty(name)) { | |
| } | |
| } |
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 rowsCombine(rows) { | |
| return rows.map(row => { | |
| return row.reduce((combine, currentCell) => combine + currentCell, 0); | |
| }); | |
| } | |
| // свести каждую колонку матрицы к одному значению (например, минимальная ширина) | |
| function colsCombine(rows) { | |
| return rows[0].map((_, 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
| if (typeof module != "undefined" && module.exports) | |
| module.exports = 'hello world'; |
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 holdBeforeFired(funcToFire, holdTime) { | |
| let hold = false, | |
| _this, | |
| _arguments; | |
| return function action() { | |
| if (hold) { | |
| _this = this; | |
| _arguments = arguments; | |
| return; |
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 bifurcateBy = (arr, fn) => | |
| arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]); |
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
| Child.prototype = Object.create(Parent.prototype); | |
| Child.prototype.constructor = Child; |
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 CustomError(message) { | |
| this.message = message; | |
| this.stack = (new Error()).stack; | |
| } | |
| CustomError.prototype = Object.create(Error.prototype); | |
| CustomError.prototype.name = "CustomError"; |