Skip to content

Commit d32c886

Browse files
committed
数组排序
1 parent 40f92f7 commit d32c886

File tree

2 files changed

+315
-114
lines changed

2 files changed

+315
-114
lines changed

README.md

Lines changed: 176 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ var func = (a, b) => {
105105

106106
**顶部变量属性**`var` 声明的变量会挂载在 window 上,而 `let``const` 声明的变量不会
107107
**变量提升**`var` 变量可在声明之前使用,`let``const` 不可以
108-
**暂时性死区**`var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,使用会抛出异常 (暂时性死区)
109-
**重复声明**`var`允许重复声明,`let``const` 命令声明的变量不允许重复声明
108+
**暂时性死区**`var`不存在暂时性死区,在代码块中,用 `let``const` 声明变量之前,使用会抛出异常 (暂时性死区)
109+
**重复声明**`var`允许重复声明,`let``const` 命令声明的变量不允许重复声明
110110
**初始值**`var``let`可以没有初始值,由于 `const` 声明的是只读的常量,一旦声明,就必须立即初始化,声明之后值不能改变
111111
**作用域**`var` 没有块级作用域,`let``const`有块级作用域
112112

@@ -121,7 +121,6 @@ var a = 2
121121

122122
console.log(b) //报错,Uncaught ReferenceError: b is not defined
123123
let b = 1
124-
125124
```
126125

127126
</p>
@@ -135,7 +134,7 @@ let b = 1
135134
<p>
136135

137136
- `forEach` `for`循环的简化,不能中断,没有 `break/continue` 方法,没有返回值。
138-
- `map` 只能遍历数组,不能中断,返回值是修改后的数组。
137+
- `map` 只能遍历数组,不能中断,返回值是修改后的数组。
139138

140139
```javascript
141140
const arr = [1, 2, 3, 4, 5]
@@ -168,12 +167,11 @@ for...in 循环出的是 key,for...of 循环出的是 value
168167
</details>
169168

170169
---
170+
171171
#### ES5,ES6 如何查找一个元素?
172172

173173
<details><summary><b>答案</b></summary>
174174
<p>
175-
176-
177175

178176
</p>
179177
</details>
@@ -233,6 +231,99 @@ fn(1, 2, 3)
233231

234232
---
235233

234+
#### JS 怎么实现一个类,怎么实例化这个类?
235+
236+
<details><summary><b>答案</b></summary>
237+
<p>
238+
239+
Javascript 传统方法是通过构造函数定义并生成新对象。
240+
241+
```javascript
242+
function Animal(type) {
243+
this.type = type
244+
}
245+
Animal.prototype.eat = function() {
246+
console.log('eat')
247+
}
248+
var dog = new Animal('dog')
249+
```
250+
251+
ES6 引入了 `CLASS` 概念,`constructor`方法就是构造函数,定义 `` 的方法时,前面不需要加 `function` 保留字,方法之前不需要逗号。
252+
253+
```javascript
254+
class Animal {
255+
constructor(type) {
256+
this.type = type
257+
}
258+
eat() {
259+
console.log('eat')
260+
}
261+
}
262+
var cat = new Animal('cat')
263+
```
264+
265+
</p>
266+
</details>
267+
268+
---
269+
270+
#### JS 怎么继承类?
271+
272+
<details><summary><b>答案</b></summary>
273+
<p>
274+
275+
```javascript
276+
// 只实现了部分继承 ,prototype上的没有被继承
277+
function Animal(type) {
278+
this.type = type
279+
}
280+
function Dog() {
281+
Animal.call(this)
282+
}
283+
284+
// ES6 实现继承
285+
class Animal {
286+
construtor(type) {
287+
this.type = type
288+
}
289+
eat() {
290+
console.log('eat')
291+
}
292+
}
293+
class Dog extends Animal {
294+
construtor(type) {
295+
supper(type)
296+
}
297+
}
298+
```
299+
300+
</p>
301+
</details>
302+
303+
---
304+
305+
#### ES6 `Set()` `Map()` 添加值得方法?
306+
307+
<details><summary><b>答案</b></summary>
308+
<p>
309+
310+
添加值方法: `Set` 使用`add`添加,`Map` 使用`set`添加
311+
312+
```javascript
313+
// Set
314+
let mySet = new Set()
315+
mySet.add(1)
316+
// Map
317+
const myMap = new Map()
318+
const o = { p: 'hello' }
319+
myMap.set(o, 'world')
320+
```
321+
322+
</p>
323+
</details>
324+
325+
---
326+
236327
#### es6 class static 解释?如何继承 static?
237328

238329
<details><summary><b>答案</b></summary>
@@ -264,6 +355,74 @@ Bar.classMethod() // 'hello'
264355

265356
---
266357

358+
#### 什么闭包,闭包有什么用?
359+
360+
<details><summary><b>答案:star:</b></summary>
361+
<p>
362+
363+
</p>
364+
</details>
365+
366+
---
367+
368+
#### JS 如何获取函数所有参数?
369+
370+
知识点:`rest参数` `类数组`
371+
372+
<details><summary><b>答案</b></summary>
373+
<p>
374+
375+
```javascript
376+
// ES5
377+
function sum() {
378+
console.log(arguments)
379+
}
380+
// ES6
381+
function sum(...rest) {
382+
// rest 是数组
383+
console.log(rest)
384+
}
385+
sum(1, 2, 3)
386+
```
387+
388+
</p>
389+
</details>
390+
391+
---
392+
393+
#### 用箭头函数实现一个数组排序?
394+
395+
知识点:`sort` `箭头函数`
396+
397+
<details><summary><b>答案</b></summary>
398+
<p>
399+
400+
```javascript
401+
const arr = [10, 5, 40, 25, 1000, 1]
402+
403+
arr.sort((a, b) => {
404+
return a - b
405+
})
406+
console.log(arr) // [1, 5, 10, 25, 40, 1000]
407+
```
408+
409+
</p>
410+
</details>
411+
412+
---
413+
414+
#### 如何用箭头函数时间一个数组排序?
415+
416+
知识点:`Object`
417+
418+
<details><summary><b>答案</b></summary>
419+
<p>
420+
421+
</p>
422+
</details>
423+
424+
---
425+
267426
#### 深拷贝和浅拷贝的区别,以及实现?
268427

269428
<details><summary><b>答案:star:</b></summary>
@@ -331,6 +490,16 @@ console.log(obj) // {username: "sunnie"}
331490

332491
---
333492

493+
#### this?
494+
495+
<details><summary><b>答案</b></summary>
496+
<p>
497+
498+
</p>
499+
</details>
500+
501+
---
502+
334503
#### `call``apply``bind`的区别,以及实现?
335504

336505
<details><summary><b>答案:star:</b></summary>
@@ -431,7 +600,7 @@ function debounce(func, delay) {
431600

432601
**`函数节流`(throttle):节流顾名思义则是将减少一段时间内触发的频率。**
433602

434-
比如:我点击一个按钮,`delay`设置 3s ,我手速超快,从来不让点击间隔时间大于 3s 函数就不执行,一旦大于了 3s 就执行了
603+
比如:我点击一个按钮,`threshhold`设置 3s, 当我点第一次点击执行函数,接下来的 3s 内点都少次都没用,直到距离第一次 3s 执行第二次
435604

436605
```javascript
437606
function throttle(fn, threshhold = 3000) {

0 commit comments

Comments
 (0)