Skip to content

Instantly share code, notes, and snippets.

View yanzhihong23's full-sized avatar
🏠
Working from home

Hom yanzhihong23

🏠
Working from home
  • Shanghai
View GitHub Profile
@yanzhihong23
yanzhihong23 / demo.js
Last active December 23, 2018 08:29
Promise.all handle exceptions
function fetchData(x) {
return new Promise((resolve, reject) => {
// mock
if (x == 3 || x == 4 || x == 5) {
reject('error');
} else {
resolve(x);
}
});
}
@yanzhihong23
yanzhihong23 / curry.js
Created December 26, 2018 05:14
curry multi add
function curry(fn) {
var res;
function curried() {
args = [].slice.call(arguments);
if (!res && args.length == fn.length) {
res = fn.apply(this, args);
return curried;
} else if (!res && args.length > fn.length) {
res = fn.apply(this, args);
@yanzhihong23
yanzhihong23 / cookie.js
Created July 26, 2019 04:01
Get cookie object
@yanzhihong23
yanzhihong23 / LRUCache-class.js
Last active September 24, 2020 08:25
LRUCache
class LRUCache {
constructor(size) {
this.size = size;
this.cache = new Map();
}
put(key, value) {
const { cache, size } = this;
if(cache.has(key)) {
cache.delete(key);