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
| REMIX EXAMPLE PROJECT | |
| Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer. | |
| It contains 3 directories: | |
| 1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name. | |
| 2. 'scripts': Holds two scripts to deploy a contract. It is explained below. | |
| 3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity. | |
| SCRIPTS |
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(fn, delay) { | |
| var timer | |
| return function () { | |
| var context = this | |
| var args = arguments | |
| clearTimeout(timer) |
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
| Array.prototype.concatAll = function() { | |
| var result = []; | |
| // 用 apply 完成 | |
| this.forEach((array) => { | |
| result.push.apply(result, array); | |
| }); | |
| return result; | |
| }; |
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
| Array.prototype.filter = function(callback) { | |
| var result = []; | |
| this.forEach((item, index) => { | |
| if(callback(item, index)) | |
| result.push(item); | |
| }); | |
| return result; | |
| } |
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
| Array.prototype.map = function(callback) { | |
| var result = []; | |
| this.forEach(function(element, index) { | |
| result.push(callback(element, index)); | |
| }) | |
| return result; | |
| } |
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 promiseRace(promises) { | |
| if (!Array.isArray(promises)) { | |
| throw new Error("promises must be an array") | |
| } | |
| return new Promise(function (resolve, reject) { | |
| promises.forEach(p => | |
| Promise.resolve(p).then(data => { | |
| resolve(data) | |
| }, err => { | |
| reject(err) |
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 promiseAll(promises) { | |
| if (!Array.isArray(promises)) { | |
| throw new Error("promises must be an array") | |
| } | |
| return new Promise(function (resolve, reject) { | |
| let promsieNum = promises.length; | |
| let resolvedCount = 0; | |
| let resolveValues = new Array(promsieNum); | |
| for (let i = 0; i < promsieNum; 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
| class Promsie { | |
| constructor(fn) { | |
| this.status = 'pending', | |
| this.resolve = undefined; | |
| this.reject = undefined; | |
| let resolve = value => { | |
| if (this.status === 'pending') { | |
| this.status = 'resolved'; | |
| this.resolve = value; | |
| } |
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 flatten = (input) => { | |
| const stack = [...input]; | |
| const result = []; | |
| while (stack.length) { | |
| const next = stack.pop(); | |
| if (Array.isArray(next)) { | |
| stack.push(...next); | |
| } else { | |
| result.push(next); | |
| } |
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 equal(n1, n2) { | |
| return Math.abs(n1 - n2) < Number.EPSILON; | |
| } | |
| var a = 0.1 + 0.2; | |
| var b = 0.3; | |
| equal(a, b); // true | |
| equal(0.0000001, 0.0000002); // false |
NewerOlder