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 clearAllInterval () { | |
let id = setInterval(function () {}, 9999); | |
while (id > 0) { clearInterval(id--); } | |
} |
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 = -1; | |
return function () { | |
var that = this; | |
var args = arguments; | |
window.clearTimeout(timer); | |
timer = window.setTimeout(function () { | |
fn.apply(that, args); | |
}, delay || 300); | |
}; |
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
{ | |
"common": { | |
"mail": { | |
"title": "Ghost 在 {domain}" | |
}, | |
"seeLinkForInstructions": "有关说明,请参阅 {link}。", | |
"time": { | |
"seconds": "秒" | |
}, | |
"api": { |
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
/** | |
* 回形矩阵 | |
* @param {Number} n - 矩阵尺寸 | |
* @return {String} | |
*/ | |
function spiralMatrix (n) { | |
let matrix = []; | |
let a = n ** 2; | |
let p = a.toString().length; | |
for (let x = 0; x < n; x++) { |
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
/** | |
* 判断质数 | |
* @param {Nubmer} nubmer | |
* @return {Boolean} | |
*/ | |
function isPrime (number) { | |
let isNumber = "number" === typeof number; | |
let isInteger = isNumber && 0 === number % 1; | |
let isNatural = isInteger && -1 < number; | |
if (!isNatural || 2 > number) { return false; } |
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
/** | |
* Promises/A+ | |
* @see http://www.ituring.com.cn/article/66566 | |
* @param {Function} executor | |
*/ | |
function MyPromise (executor) { | |
let PromiseStatus = "pending"; | |
let PromiseValue = undefined; | |
let PromiseTasks = []; |
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
/** | |
* 查找出现频率最高项 | |
* @param {Array} array | |
*/ | |
function findMostFreq (array) { | |
let freqs = {}; | |
let length = array.length; | |
let result = { item: undefined, freq: 0 }; | |
for (let i = 0; i < length; i++) { | |
let item = array[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
/** | |
* 对象深拷贝 | |
*/ | |
function deepCopy (object, pairs = []) { | |
let copy = {}; | |
pairs.push([object, copy]); | |
for (let key in object) { | |
if (object.hasOwnProperty(key)) { | |
let value = object[key]; | |
if (Array.isArray(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
/** | |
* 快速排序 | |
* @param {Array} array - 乱序数组 | |
*/ | |
function quickSort (array) { | |
if (0 === array.length) { return array; } | |
let key = array.shift(); | |
let lessers = []; | |
let greaters = []; | |
for (let i = 0, item = null; item = array[i]; 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
function lazyMan (name) { | |
let man = { name }; | |
let tasks = []; | |
let excute = () => { | |
let task = tasks.shift(); | |
task && task(); | |
}; | |
man.talk = () => { | |
tasks.push(() => { | |
console.log(`Hi! This is ${name}!`); |
NewerOlder