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
function quickSort(arr) { | |
if (arr.length < 2) return arr; | |
const pivot = arr[~~(0 + Math.random() * arr.length)]; | |
return [ | |
...quickSort(arr.filter(v => v < pivot)), | |
...arr.filter(v => v === pivot), | |
...quickSort(arr.filter(v => v > pivot)), | |
]; |
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 create | |
class Lazyman { | |
constructor(name) { | |
this.task = []; | |
const fn = () => { | |
console.log(`Hi! This is ${name}`); | |
this.next(); | |
} | |
this.task.push(fn); | |
setTimeout(() => { |
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
// Extend copy | |
function extendCopy(o) { | |
let c = {}; | |
for (let i in o) { | |
c[i] = o[i]; | |
} | |
c.uber = o; | |
return c; |
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
// Use recursion | |
function flatten(arr) { | |
let result = []; | |
arr.forEach(el => { | |
if (el instanceof Array) { | |
result = result.concat(flatten(el)); | |
} else { | |
result.push(el); | |
} | |
}); |
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 LruCache { | |
constructor(maxsize) { | |
this._cache = {}; // 缓存 | |
this._queue = []; // 队列 | |
this._maxsize = maxsize; // 最大值 | |
// 如果最大值输入非法 默认无限大 | |
if (!this._maxsize || !(typeof this._maxsize === 'number') || this._maxsize <= 0) { | |
this._maxsize = Infinity; | |
} |
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
# _/_/_/_/ _/_/_/ _/_/_/ | |
# _/ _/ _/ _/ | |
# _/_/_/ _/_/_/ _/ | |
# _/ _/ _/ _/ | |
# _/ _/_/_/ _/_/_/ | |
_COLUMNS=$(tput cols) | |
_MESSAGE=" FBI Warining " | |
y=$((($_COLUMNS - ${#_MESSAGE}) / 2)) | |
spaces=$(printf "%-${y}s" " ") |
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
.vuepress-plugin-demo-block__wrapper .vuepress-plugin-demo-block__footer:hover .vuepress-plugin-demo-block__expand::before, | |
.vuepress-plugin-demo-block__wrapper .vuepress-plugin-demo-block__footer:focus .vuepress-plugin-demo-block__expand::before, | |
.vuepress-plugin-demo-block__wrapper .vuepress-plugin-demo-block__footer:visited .vuepress-plugin-demo-block__expand::before { | |
border-top-color: #2B66C4 !important; | |
border-bottom-color: #2B66C4 !important; | |
} | |
.vuepress-plugin-demo-block__wrapper .vuepress-plugin-demo-block__footer .vuepress-plugin-demo-block__expand::before, | |
.vuepress-plugin-demo-block__wrapper .vuepress-plugin-demo-block__footer svg { | |
transition: all .2s ease; |
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
function toUnderscore(string) { | |
return string.toString().split(/(?=[A-Z])/).join('_').toLowerCase(); | |
}; |
![I.gif](https://gist.github.com/HuangXiZhou/a70369438c24d77b1415ce62fd0e5d84/raw/748c2e6a4e39b939a91bfc2f98dc1566a6deb9bb/I.gif)
![AM.gif](https://gist.github.com/HuangXiZhou/26d9f10f0b0d99f877223e92cb69d8d1/raw/be5e9ec2f3c82940b4939ed69f9027a4a693c0be/AM.gif)
OlderNewer