This file contains 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
/* | |
e.g. | |
levenshteinDistance("aa","a") = 1; | |
levenshteinDistance("ab","ab") = 1; | |
levenshteinDistance("a","b") = 1; | |
*/ | |
var levenshteinDistance = function(s, t) { | |
var d = []; //2d matrix | |
// Step 1 |
This file contains 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 Array.isArray==="undefined"){ | |
Array.isArray = function(args){ | |
return Object.prototype.toString.call(args) === "[object Array]"; | |
}; | |
}//else{ | |
//p("call default isArray()" + Array.isArray(a)) | |
//} |
This file contains 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
/* | |
location.search == '?a=1&b=&c | |
return {a:'1',b:''} | |
//注意是字符串…… | |
*/ | |
function getUrlParams() { | |
var qs = location.search.split("+").join(" "); | |
var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); | |
return params; |
This file contains 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 Task { | |
constructor(task, taskParam, delay) { | |
this.task = task; // 传入一个需要被执行的函数 | |
this.taskParam = taskParam; // task的参数,一个或多个参数装载数组里!数组里!数组里! | |
this.delay = delay || 0; | |
} | |
action() { | |
// ... | |
typeof this.task === 'function' && this.task.apply(null, this.taskParam); | |
} |
This file contains 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
// Promise, async, await 快速教程 | |
// 包含异步执行顺序控制、异常控制、多异步排序控制 | |
// t1 多异步串行、异常处理 | |
function t1(){ | |
function stepA(){ | |
return new Promise((resolve, reject) => { | |
setTimeout(()=>{ | |
Math.random() > 0.5 ? resolve('A') : reject('~A~') | |
}, 300) |