Skip to content

Commit e628139

Browse files
author
黄正
committed
feat: add about me page
1 parent fac0a8d commit e628139

File tree

4 files changed

+80
-68
lines changed

4 files changed

+80
-68
lines changed

source/_posts/js常用工具函数.md

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,107 +10,112 @@ tags:
1010
## 数组
1111

1212
### 判断是否存在重复的元素
13+
1314
```js
14-
const isRepeat = (arr) => {
15-
let hash = {};
16-
for(let i in arr) {
17-
if(hash[arr[i]]) {
18-
return true;
19-
}
20-
hash[arr[i]] = true;
21-
}
22-
return false;
15+
const isRepeat = (arr) => {
16+
let hash = {};
17+
for (let i in arr) {
18+
if (hash[arr[i]]) {
19+
return true;
2320
}
24-
21+
hash[arr[i]] = true;
22+
}
23+
return false;
24+
};
2525
```
2626

2727
e.g:
28+
2829
```js
29-
const arr = ['hello', 'world', 'hello', 'kitty'];
30-
isRepeat(arr) // true
30+
const arr = ['hello', 'world', 'hello', 'kitty'];
31+
isRepeat(arr); // true
3132
```
3233

33-
### 按数组顺序查找缺失的第一项(从0开始)
34+
### 按数组顺序查找缺失的第一项(从 0 开始)
3435

3536
```js
36-
const findMissing = (arr, key = 'index') => {
37-
let missing = null;
38-
for (let i = 0; i < arr.length; i++) {
39-
const result = arr.find(item => {
40-
if (typeof item === 'object') {
41-
return key in item && i === item[key];
42-
} else {
43-
return i === item;
44-
}
45-
});
46-
if (!result) {
47-
missing = i;
48-
break;
49-
} else {
50-
continue;
51-
}
52-
}
53-
return missing;
37+
const findMissing = (arr, key = 'index') => {
38+
let missing = null;
39+
for (let i = 0; i < arr.length; i++) {
40+
const result = arr.find((item) => {
41+
if (typeof item === 'object') {
42+
return key in item && i === item[key];
43+
} else {
44+
return i === item;
45+
}
46+
});
47+
if (!result) {
48+
missing = i;
49+
break;
50+
} else {
51+
continue;
5452
}
53+
}
54+
return missing;
55+
};
5556
```
5657

5758
e.g:
59+
5860
```js
59-
const a = [0,2,4,1,5]
60-
const m = this.findMissing(a); // 3
61+
const a = [0, 2, 4, 1, 5];
62+
const m = this.findMissing(a); // 3
6163

62-
const a = [{i:0},{i:3},{i:1},{i:6}];
63-
const m = this.findMissing(a, 'i'); // 2
64+
const a = [{ i: 0 }, { i: 3 }, { i: 1 }, { i: 6 }];
65+
const m = this.findMissing(a, 'i'); // 2
6466
```
6567

6668
### 移动数组元素到某个位置
6769

6870
```js
69-
const moveItem = function(arr, fromIndex, toIndex) {
70-
const len = arr.length;
71-
if (toIndex > len - 1) {
72-
toIndex = len - 1;
73-
}
74-
for (const k in arr) {
75-
const item = arr[k];
76-
if (k == fromIndex) {
77-
arr.splice(k, 1);
78-
arr.splice(toIndex, 0, item);
79-
break;
80-
}
81-
}
82-
return arr;
83-
};
71+
const moveItem = function (arr, fromIndex, toIndex) {
72+
const len = arr.length;
73+
if (toIndex > len - 1) {
74+
toIndex = len - 1;
75+
}
76+
for (const k in arr) {
77+
const item = arr[k];
78+
if (k == fromIndex) {
79+
arr.splice(k, 1);
80+
arr.splice(toIndex, 0, item);
81+
break;
82+
}
83+
}
84+
return arr;
85+
};
8486
```
87+
8588
e.g:
89+
8690
```js
87-
const arr = [1,2,3,4,5];
88-
//将下标2的元素移动到4位置
89-
moveItem(arr, 2, 4) // [1,2,4,5,3]
91+
const arr = [1, 2, 3, 4, 5];
92+
//将下标2的元素移动到4位置
93+
moveItem(arr, 2, 4); // [1,2,4,5,3]
9094
```
9195

9296
## 字符串
9397

9498
### 测试字符长度,中文算两个字符
9599

96100
```js
97-
const strlen = (str) => {
98-
let len = 0;
99-
for (let i=0; i<str.length; i++) {
100-
let c = str.charCodeAt(i);
101-
if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
102-
len++;
103-
} else {
104-
len+=2;
105-
}
106-
}
107-
return len;
101+
const strlen = (str) => {
102+
let len = 0;
103+
for (let i = 0; i < str.length; i++) {
104+
let c = str.charCodeAt(i);
105+
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
106+
len++;
107+
} else {
108+
len += 2;
108109
}
110+
}
111+
return len;
112+
};
109113
```
110114

111115
e.g:
116+
112117
```js
113-
strlen('你好123'); // 7
118+
strlen('你好123'); // 7
114119
```
115120

116-
未完待续...
121+
未完待续...

source/_posts/关于我.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: 关于我
3+
catalog: true
4+
date: 2022-03-11 12:49:13
5+
subtitle:
6+
header-img:
7+
tags:
8+
---

source/img/avatar/ironman.png

-249 KB
Binary file not shown.

themes/aboy/layout/_partial/footer.ejs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@
8383
<p class="copyright text-muted">
8484
Copyright &copy; <%= config.author %> <%= new Date().getFullYear() %>
8585
<br>
86-
Theme by <a href="http://beantech.org">BeanTech</a>
8786
<span style="display: inline-block; margin: 0 5px;">
8887
<i class="fa fa-heart"></i>
8988
</span>
90-
re-Ported by <a href="https://l20.github.com/blog">Loksin</a> |
89+
Ported by <a href="https://l20.github.io/blog/">Loksin</a> |
9190
<iframe
9291
style="margin-left: 2px; margin-bottom:-5px;"
9392
frameborder="0" scrolling="0" width="91px" height="20px"

0 commit comments

Comments
 (0)