sv-98-maxin
sv-98-maxin
```javascript function treeToList(treeData, result = []) { treeData.forEach(item => { if (item.children) { treeToList(item.children, result) delete item.children } result.push(item) }) return result } ```
> Why we can use `DeepMutable` directly? `T[k]` can be primitive, and why it doesn't tigger the generic constraint `T extends Record`? because T[K] extends any ?
``` function instanceOf(left, right) { let a = Object.getPrototypeOf(left), b = right.prototype; while (a) { if (a === b) { return true } a = Object.getPrototypeOf(a) } return false }...
> @Lionad-Morotar as bottom type why `T extends never` fail `[T] extends [never]` worded you can study this [chapter](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types)
``` function getKey(obj, str) { if (/\[/g.test(str)) { str = str.replaceAll(/\[/g, '.').replaceAll(/\]/g, '') } const keyArr = str.split('.') for (const k of keyArr) { obj = obj[k] } return obj...
``` Array.prototype.myFlat = function (depth = 1) { const flat = arr => { return arr.reduce((prev, next) => { if (Array.isArray(next)) { prev.push(...next) } else { prev.push(next) } return prev...
```javascript let arr = [ { id: '1', name: '父节点1', pid: undefined }, { id: '1-1', name: '子节点1-1', pid: '1' }, { id: '1-1-1', name: '子节点1-1-1', pid: '1-1' }, {...
``` Promise.myAll = promises => { // 参数需要是一个可迭代对象 if(typeof promises[Symbol.iterator] !== 'function'){ throw(`${promises}不是一个可迭代对象`) } promises = [...promises] const len = promises.length, result = []; //存放结果 let count = 0 //promise完成的个数...