Skip to content

Commit

Permalink
feat: 0711
Browse files Browse the repository at this point in the history
  • Loading branch information
niaogege committed Jul 11, 2023
1 parent d698d3c commit 2275627
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 1 deletion.
173 changes: 173 additions & 0 deletions docs/interview/experiences/12interview0703.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
title: 面试经验之积累常见面试题
order: 12
group:
order: 0
title: interview
nav:
order: 3
title: 'interview'
path: /interview
---

[5 年前端,面试经验](https://mp.weixin.qq.com/s/HfN-ULy9KD86vTuzDDFIiw)

- vue 和 react 在虚拟 dom 的 diff 上,做了哪些改进使得速度很快?
- vue 的 keep-alive 原理以及生命周期

- 【代码题】 实现一个节流函数? 如果想要最后一次必须执行的话怎么实现?

- 【代码题】 实现一个批量请求函数, 能够限制并发量?
- 使用 Promise 实现一个异步流量控制的函数, 比如一共 10 个请求, 每个请求的快慢不同, 最多同时 3 个请求发出, 快的一个请求返回后, 就从剩下的 7 个请求里再找一个放进请求池里, 如此循环。

- 数组转树结构

```js
const arr = [
{
id: 2,
name: '部门B',
parentId: 0,
},
{
id: 3,
name: '部门C',
parentId: 1,
},
{
id: 1,
name: '部门A',
parentId: 2,
},
{
id: 4,
name: '部门D',
parentId: 1,
},
{
id: 5,
name: '部门E',
parentId: 2,
},
{
id: 6,
name: '部门F',
parentId: 3,
},
{
id: 7,
name: '部门G',
parentId: 2,
},
{
id: 8,
name: '部门H',
parentId: 4,
},
];
```

- 去除字符串中出现次数最少的字符,不改变原字符串的顺序

```js
“ababac” —— “ababa”
“aaabbbcceeff” —— “aaabbb”
```

- 写出一个函数 trans,将数字转换成汉语的输出,输入为不超过 10000 亿的数字。

```js
trans(123456) —— 十二万三千四百五十六
trans(100010001)—— 一亿零一万零一
```

- async await 的原理是什么?
- redux 原理
- webscoket 的连接原理
- 数组转树, 写完后问如果要在树中新增节点或者删除节点, 函数应该怎么扩展

```js
const arr = [
{
id: 2,
name: '部门B',
parentId: 0,
},
{
id: 3,
name: '部门C',
parentId: 1,
},
{
id: 1,
name: '部门A',
parentId: 2,
},
{
id: 4,
name: '部门D',
parentId: 1,
},
{
id: 5,
name: '部门E',
parentId: 2,
},
{
id: 6,
name: '部门F',
parentId: 3,
},
{
id: 7,
name: '部门G',
parentId: 2,
},
{
id: 8,
name: '部门H',
parentId: 4,
},
];
```

- Node 是怎么部署的? pm2 守护进程的原理?
- Node 的日志和负载均衡怎么做的
- Node 开启子进程的方法有哪些?
- node 服务治理
- 给一个字符串, 找到第一个不重复的字符

```js
ababcbdsa;
abcdefg;
```

- Promise then 第二个参数和 catch 的区别是什么?
- Promise finally 怎么实现的
- useRef / ref / forwardsRef 的区别是什么?

- 各种缓存的优先级, memory disk http2 push?
- 小程序为什么会有两个线程? 怎么设计?
- xss? 如何防范?

- 多叉树, 获取每一层的节点之和

```js
function layerSum(root) {}

const res = layerSum({
value: 2,
children: [
{ value: 6, children: [{ value: 1 }] },
{ value: 3, children: [{ value: 2 }, { value: 3 }, { value: 4 }] },
{ value: 5, children: [{ value: 7 }, { value: 8 }] },
],
});

console.log(res);
```

- 多叉树指定层节点的个数
- 二叉树层序遍历, 每层的节点放到一个数组里
- 截图怎么实现
- js 超过 Number 最大值的数怎么处理?
30 changes: 30 additions & 0 deletions docs/interview/experiences/2baseWriting.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ nav:

### mockMap/mockFilter 数组方法重写

```js
Array.prototype.mockMap = function (fn, context) {
var arr = Array.prototype.slice.call(this) || []
var res = []
for (let i = 0; i < arr.length; i ++) {
res.push(fn.call(context, arr[i], i, arr)))
}
return res
}
```

### myReduce 重写

```js
Expand All @@ -51,3 +62,22 @@ console.log(sum, 'sum');
var sum2 = [1, 2].myReduce((a, b) => a + b, 10);
console.log(sum2, 'sum');
```

### myFlat

```js
Array.prototype.myFlat = function (num = 1) {
var arr = Array.prototype.slice.call(this) || [];
var i = 0;
while (arr.some((e) => Array.isArray(e))) {
console.log(arr, 'before');
arr = [].concat(...arr);
console.log(arr, 'after');
i++;
if (i >= num) break;
}
return arr;
};
var test = [1, [2, 3, 4], [[5, 6, 7]]];
test.myFlat();
```
6 changes: 6 additions & 0 deletions docs/interview/experiences/practise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
9.16进制转rgb or rgb转16进制
10.mockMap/mockFilter 数组方法重写
11.mockMap
//////////
12.mockReduce
13.pipe
14.ajax
15.EventEmitter
16.flatten/mockFlat
*/

Function.prototype.myCall = function (context, ...rest) {
Expand Down
2 changes: 1 addition & 1 deletion docs/interview/experiences/practise2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Required1<T> = {
};
type E20 = Required1<TT2>;

type E22 = Subsequence<[1, 2, 3]>;
type E22 = Subsequence2<[1, 2, 3]>;
type Subsequence2<T> = T extends [infer F, ...infer R]
? Subsequence2<R> | [F, ...Subsequence2<R>]
: T;
Expand Down
27 changes: 27 additions & 0 deletions docs/interview/js/29.js BigInt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: js BigInt大数
order: 29
group:
order: 1
title: js Basic
path: /interview/js
nav:
order: 3
title: 'interview'
path: /interview
---

[js 超过 Number 最大值的数怎么处理](https://www.cnblogs.com/wangmeijian/p/9217352.html)

JavaScript 中的基本数据类 Number 是双精度浮点数,它可以表示的最大安全范围是正负 9007199254740991,也就是 2 的 53 次方减一,在浏览器控制台分别输入**Number.MAX_SAFE_INTEGER 和 Number.MIN_SAFE_INTEGER**可查看对应的最大/小值

BigInt 是 JavaScript 中的一个新的原始类型,可以用任意精度表示整数。使用 BigInt,即使超出 JavaScript Number 的安全整数限制,也可以安全地存储和操作大整数。

chrome 67+开始支持 BigInt,本文所有 demo 都是基于 chrome 67。

要创建一个 BigInt,在数字后面添加 n 后缀即可,例如,123 变成 123n。全局 BigInt(number)函数可以用来将 Number 转换成 BigInt。换句话说,BigInt(123) === 123n。让我们用这两种技术来解决我们之前遇到的问题:

```js
BigInt(Number.MAX_SAFE_INTEGER) + 2n;
// 9007199254741103n
```
27 changes: 27 additions & 0 deletions docs/interview/logic/hot100.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ nav:
path: /interview
---

### 输出 100 内的所有质数

> 质数又称素数。一个大于 1 的自然数,除了 1 和它自身外,不能整除其他自然数的数叫做质数 2 是 1/0 都不是质数 也不是合数大于 1 且除 1 和这个数本身,还能被其他正整数整除的整数
```js
function isPrime(n) {
const max = Math.ceil(Math.sqrt(n));
if (n === 2) return true;
for (let counter = 2; counter <= max; counter++) {
if (n % counter === 0) {
return false;
}
}
return true;
}
function primeList(n) {
let arr = [];
for (let num = 2; num < n; num++) {
if (isPrime(num)) {
arr.push(num);
}
}
return arr;
}
primeList(100);
```

> 把握最后一次翻身机会,如果算法搞不定,什么都没有希望! 20230120 春节期间 对未来的彷徨和无奈 让你不得不面对现实压力,还是得需要把简单的算法捡球来
> 十天过去了 一题没刷
Expand Down

0 comments on commit 2275627

Please sign in to comment.