xiaoy
xiaoy
给定一个升序整数数组[0,1,2,4,5,7,13,15,16],找出其中连续出现的数字区间如下: ["0->2","4->5","7","13","15->16"] ```js const arr = [0, 1, 2, 4, 5, 7, 13, 15, 16] function getArr(arr) { let j, ans = [], str = ''; for (let i =...
思考:有没有考虑过LRU算法实现中为什么使用map,它的好处是什么?对于LRU算法,是get使用频率更高还是put使用频率更高?为什么?LRU算法的使用场景? —— 莉莉丝日常实习面试
题目: ```js new Quene() .task(1000, () => { console.log(1) }) .task(2000, () => { console.log(2) }) .task(1000, () => { console.log(3) }) .start() function Quene() { ... } //补全代码 ```...
算法题:字符串重命名。 举例 ,输入["ab","c","ab","c","a","d"], 输出["ab1","c1","ab2","c2","a","d"], 输出不可以改变原有顺序,不重复的字符串不动。 ```js const arr = ['ab', 'c', 'ab', 'd', 'c'] function getArr(arr){ for(let i=0; i
方式一:promise写法 ```js function myPromise(time, context){ return new Promise((resolve, reject) => { setTimeout(() => { console.log(context); resolve() }, time); }) } // promise写法 myPromise(1000, 111) .then(() => { return myPromise(2000, 222);...
``` HTML Document 11111 22222222 333333333 展示 function Router(){ this.routes={} this.curUrl='' //添加回调函数 this.route=function(path,callback){ this.routes[path]=callback||function(){} } //执行回调函数 this.refresh=function(){ //获取url this.curUrl=location.hash.slice(1)||'/' this.routes[this.curUrl]() } //监听load和hashchange this.init=function(){ window.addEventListener('load',this.refresh.bind(this),false) window.addEventListener('hashchange',this.refresh.bind(this),false) } } let res=document.getElementById('div') let...
实现一个函数, 把一个字符串数组([‘zm’, ‘za’, ‘b’, ‘lm’, ‘ln’, ‘k’]) 格式化成一个对象 { ‘b’: [‘b’], ‘k’: [‘k’], ‘l’: [‘lm’, ‘ln’], ‘z’: [‘za’, ‘zm’] } ```js const arr = ['zm', 'za', 'b', 'lm', 'ln', 'k']...
hi, when to merge?
单测是否可以参考这个 wiki: [TinyVue 高频组件列表](https://github.com/opentiny/tiny-vue/wiki/TinyVue-%E9%AB%98%E9%A2%91%E7%BB%84%E4%BB%B6%E5%88%97%E8%A1%A8)
```js function changeFormat(arr){ let res = []; let map = new Map(); arr.forEach(item => { let categories = item.categories; categories.map(keyWord => { if(!map.has(keyWord)){ map.set(keyWord, [item.name]); }else{ map.get(keyWord).push(item.name); } }) })...