kungithub
kungithub
``` javascript let list = [{ id: '1', children: [{ id: '11', children: [{ id: '111' }, { id: '112' }] }] }]; function fn(value) { // 回溯的标记 let _p...
``` javascript function out(value){ if(value.length===0) return ''; value = Array.isArray(value)?value:value.toString().split(''); return value.pop() + out(value); } ```
function f(arr,k){arr.unshift(...arr.splice(-k)); console.log(arr) }
'AbcDefGh'.replace(/[a-zA-Z]/g,function(a){ return /[a-z]/.test(a)?a.toUpperCase():a.toLowerCase(); });
``` javascript // 方法1 利用for的变量i 输出99-0 function print(n){ setTimeout(() => { console.log(--i); }, Math.floor(Math.random() * 1000)); } for(var i = 0; i < 100; i++){ print(i); } //方法2 将setTimeout 的时间改为...
> > ```js > > // 方法1 利用for的变量i 输出99-0 > > function print(n){ > > setTimeout(() => { > > console.log(--i); > > }, Math.floor(Math.random() * 1000)); > > }...
> 每次跑循环的时候,setTimeout里的n都已经确定为对应的数字了,之后真正执行的时候,没有作用域查找n这个过程了。这样子吗? 你理解的偏太远了,timer方法作用域内没有找到n,于是去上一级作用域链print方法内找,找到了n,就是一个值,结束。和外面的for没一点关系了,你自己先想想。
``` javascript function mid(arr1, arr2) { function findIndex(kArray) { let value; let tmp = 0; let k = kArray[tmp]; let result = []; function find(arr, i, j) { if (i...
``` javascript function deepClone(obj, hash = new WeakMap()) { if (hash.has(obj)) return obj; var cobj; // null if (obj === null) { return obj } let t = typeof obj;...