Skip to content

Commit

Permalink
feat: 0517
Browse files Browse the repository at this point in the history
  • Loading branch information
niaogege committed May 17, 2024
1 parent cb6bb4f commit ab07d3f
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 16 deletions.
Empty file.
97 changes: 82 additions & 15 deletions docs/interview/guide/8hardHandwriting.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,21 @@ function to36(num, radix = 36) {
to36('360');
```

## 5.
## 5.根据以下数组对 born 进行降序排序

```js
var singers = [
{ name: 'Steven Tyler', band: 'Aerosmith', born: 1948 },
{ name: 'Karen Carpenter', band: 'The Carpenters', born: 1950 },
{ name: 'Kurt Cobain', band: 'Nirvana', born: 1967 },
{ name: 'Stevie Nicks', band: 'Fleetwood Mac', born: 1948 },
];
function test(arr) {
// return arr.sort((a, b) => b.born - a.born);
return arr.sort((a, b) => (a.born < b.born ? 1 : -1));
}
test(singers);
```

## 6.判断对象是否存在循环引用

Expand Down Expand Up @@ -171,21 +185,19 @@ function isCycleObj(obj) {

```js
function redPacket(total, num, max = 2, min = '0.1') {
function name(params) {
let remain = total;
let ans = [];
for (let i = 0; i < num - 1; i++) {
let Max = (remain / num) * max;
let cur = Math.floor(Max * Math.random() * 100) / 100;
cur = cur < min ? min : cur;
ans.push(cur);
remain = Math.round((remain - cur) * 100) / 100;
}
ans.push(remain);
return ans;
let remain = total;
let ans = [];
for (let i = 0; i < num - 1; i++) {
let Max = (remain / num) * max;
let cur = Math.floor(Max * Math.random() * 100) / 100;
cur = cur < min ? min : cur;
ans.push(cur);
remain = Math.round((remain - cur) * 100) / 100;
}
redPacket(10, 4);
ans.push(remain);
return ans;
}
redPacket(10, 4);
```

## 8.封装异步的 fetch,使用 async await 方式来使用
Expand Down Expand Up @@ -265,7 +277,62 @@ function mockData() {
}
```
## 11.
## 11.编写 vue 组件,组件内部使用插槽接收外部内容,v-model 双向绑定,实现折叠展开功能
```html
<template>
<div>
<button @click="toggleCollapse">{{ collapsed ? '展开' : '折叠' }}</button>
<div v-show="!collapsed">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
model: {
prop: 'collapsed',
event: 'toggle',
},
props: {
collapsed: {
type: Boolean,
default: true,
},
},
methods: {
toggleCollapse() {
this.$emit('toggle', !this.collapsed);
},
},
};
</script>
```
在使用该组件时,可以使用 v-model 来进行双向绑定:
```html
<template>
<div>
<Panel v-model="isCollapsed">
<div>需要折叠展开的内容</div>
</Panel>
</div>
</template>
<script>
import Panel from './components/Panel.vue';
export default {
components: {
Panel,
},
data() {
return {
isCollapsed: true,
};
},
};
</script>
```
## 链接
Expand Down
1 change: 0 additions & 1 deletion docs/node/nestjs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ nav:
- [nestjs](https://juejin.cn/post/7032079740982788132?searchId=202404061303234D363E19D3DDF005014F)
- [nestjs-guide](https://pengtikui.cn/blog/nestjs-guide)
- [nestjs](https://docs.nestjs.cn/9/firststeps)
- []()
- [五月君大佬图片压缩](https://github.com/qufei1993/compressor)
> 发现自己有这么多的缺点和不懂的点,需要主动学习,什么时候才能想五月君大佬,写出这么优雅的代码出来?
Expand Down
19 changes: 19 additions & 0 deletions docs/ts/handwritingTs.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,22 @@ type NumberRange<
R extends number = never,
> = U['length'] extends P ? R | U['length'] : NumberRange<T, P, [0, ...U], R | U['length']>;
```
### 如何约束函数返回值类型
```ts
const obj = { a: 1, b: '2' } as const;
function fn<T>(obj: T, param: keyof T) {
return obj[param];
}
const test = fn(obj, 'a'); // const test: 1 | "2"
```
如何是的 test 类型为 1
```ts
function fn2<T, K extends keyof T>(obj: T, param: K) {
return obj[param];
}
const test2 = fn2(obj, 'a'); // const test2: 1
```
6 changes: 6 additions & 0 deletions docs/ts/practise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,9 @@ type E28 = Equal<E251, { hobby: string; name: symbol }>;
type T26 = Promise<[Promise<{ name: 'cpp' }>, 2, 3]>;
type MyPromise<T> = T extends Promise<infer A> ? A : never;
type T27 = MyPromise<T26>;

const obj = { a: 1, b: '2' } as const;
function fn<T, K extends keyof T>(obj: T, param: K) {
return obj[param];
}
const test = fn(obj, 'a');

0 comments on commit ab07d3f

Please sign in to comment.