yanglongfei

Results 10 comments of yanglongfei

这个问题我在去年的时候遇到过,当时是这么解决的,我记录到自己的博客园里了,欢迎批评指正http://www.cnblogs.com/windseek/p/6370861.html

const map = new Map(); const cacheFn = function(fn) { return function(...args) { if( map.get(args)) { return map.get(args) } return map.set(args, fn.appy(this, args)); } }

function requestAbort() { return new Promise((rs, rj) => { setTimeout( () => rj('请求失败') , 5000); }) } function request(t) { return new Promise((rs, rj) => { setTimeout( () => rs('请求成功')...

> 思考:有没有考虑过LRU算法实现中为什么使用map,它的好处是什么?对于LRU算法,是get使用频率更高还是put使用频率更高?为什么?LRU算法的使用场景? —— 莉莉丝日常实习面试 map存储的时候有顺序,实现了Iterator接口

` const useState = (v) => { const setV = (_v) => { v = _v }; render(); return [v, setV] } `

function transfrom (number) { let rs = ''; let num = number; while(num) { let cur = num%2; num = Math.floor(num/2); rs = cur + '' + rs; } return...

const targetArray = [1, [2, 3], 4]; const formater = '[a, [b], c]'; const formaterArray = ['a', ['b'], 'c']; const destructuringArray = (values, keys) => { try { const obj...

function log() { console.log.apply(console, arguments) }

`function loadImgAsync(url) { let img = new Image(url); return new Promise((rs, rj) => { img.onload = () => { rs(); } img.onerror = () => { rj(); } img.src =...

let url = 'www.baidu.toutiao.com' function reverse(str) { let _str = ''; let _item = ''; for(var i = 0; i < str.length; i++) { if(str[i] != '.') { _item =...