Lingdeqing

Results 8 comments of Lingdeqing

**var,已废弃** 1. 函数作用域 & 全局作用域 2. 存在声明提升 **let/const,更现代** 1. 块级作用域 2. 不能重复声明 3. 在声明后才可用,存在死区

```javascript function add(a) { var curSum = a; function res(b) { curSum += b return res } res.toString = function () { return curSum } return res } ```

### 0~99 ```javascript function print(n){ setTimeout((() => { console.log(99); return () => {} })(), Math.floor(Math.random() * 1000)); } for(var i = 0; i < 100; i++){ print(i); } ``` ###...

```javascript Promise._all = function (promises) { return new Promise((resolve, reject) => { const result = [], resolved = 0 const length = promises.length const addResult = (item, index) => {...

将选中的元素和最后的元素进行交换,时间复杂度O(中奖人数) ```javascript function choujiang(all, n) { const result = [] for (let i = 0; i < n; i++) { const random = Math.floor(Math.random() * (all.length - i)) result.push(all[random]) [all[random],...

```javascript // 单向链表 class ListNode{ constructor(val, next=null){ this.val = val this.next = next } } class List { #head = null; #size = 0; // 末尾追加节点 appendNode(newNode){ if(this.isEmpty()){ this.#head =...

1. 先把对象key排序 2. 再用map去重 ``` function removeDupObj(items) { const map = new Map() items.forEach(item => { const keySortedObj = sortObjKeys(item) map.set(JSON.stringify(keySortedObj), item) }) return [...map.values()] } function sortObjKeys(obj) { if...

没有这么复杂吧,就最内层次数是一样的 ![image](https://user-images.githubusercontent.com/21056292/158058519-b7aa076e-a6b1-4cb4-9715-c709b92effb5.png)