Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5e38d6

Browse files
committed
更新
1 parent 53b6a7a commit b5e38d6

12 files changed

+203
-62
lines changed

‎Topics/招聘/2021秋招-网易互联网笔试.js‎ renamed to ‎Topics/2021秋招-网易互联网笔试.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ function judge(num) {
3838
if (num % i == 0) return i
3939
}
4040
return false
41-
}
42-
41+
}
File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// 2021秋招-小红书笔试
2+
3+
// 1.url 获取 key 的 value 值
4+
function solveMeFirst1(url, key) {
5+
let s = '&';
6+
if (!url.includes('&')) s = '?';
7+
const arr = url.split(s);
8+
for (let i = 0; i < arr.length; i++) {
9+
if (arr[i].includes(key)) {
10+
const index = arr[i].indexOf(key) + key.length + 1;
11+
return arr[i].slice(index);
12+
}
13+
}
14+
return false
15+
}
16+
17+
console.log(solveMeFirst1('https://m.xiaohongshu.com?key=888','key')); // 888
18+
console.log(solveMeFirst1('https://m.xiaohongshu.com?name=95919&key=888','key')); // 888
19+
console.log(solveMeFirst1('https://m.xiaohongshu.com?name=95919&key=888','name')); // 95919
20+
21+
// 3.字符串相邻去重
22+
function solveMeFirst3(str) {
23+
const arr = Array.from(str);
24+
let res = arr[0].toString();
25+
for (let x = 1; x < arr.length; x++) {
26+
if (arr[x] !== arr[x - 1]) res = res + arr[x]
27+
}
28+
return res;
29+
}
30+
31+
console.log(solveMeFirst3('AAAABBBCCDAABBB'));

‎Topics/招聘/2021秋招-富途一面.js‎ renamed to ‎Topics/二维数组组合.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 2021秋招-富途一面
22

3-
// 2.输入:[['red', 'green'], ['a1', 'a2'], ['b1', 'b2']]
3+
// 2.二维数组组合:输入:[['red', 'green'], ['a1', 'a2'], ['b1', 'b2']]
44
// 编写一个函数,要求输出:['red-a1-b1', 'red-a1-b2', 'red-a2-b1', 'red-a2-b2',
55
// 'green-a1-b1', 'green-a1-b2','green-a2-b1','green-a2-b2']
66

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// 2021秋招-深信服一面
2+
3+
// 1.关键字搜索树:写一个过滤函数,输入一个树和一个字符串,如:
4+
tree = [
5+
{'name': 'A'},
6+
{'name': 'B', 'children': [
7+
{'name': 'A'},
8+
{'name': 'AA'}
9+
]}
10+
]
11+
// 当输入字符串为'A'时,输出为
12+
[
13+
{'name': 'A'},
14+
{'name': 'B', 'children': [
15+
{'name': 'A'}
16+
]}
17+
]
18+
// 当输入字符串为'AA'时,输出为
19+
[
20+
{'name': 'A'},
21+
{'name': 'B', 'children': [
22+
{'name': 'AA'}
23+
]}
24+
]
25+
// 当输入字符串为'B'时,输出为
26+
[
27+
{'name': 'B', 'children': [
28+
{'name': 'A'},
29+
{'name': 'AA'}
30+
]}
31+
]
32+
33+
function filter(tree, str) {
34+
const result = JSON.parse(JSON.stringify(tree));
35+
(function (arr) {
36+
arr.forEach(val => {
37+
for (const i of Object.keys(val)) {
38+
if (val[i] instanceof Array) arguments.callee(i)
39+
else {
40+
if (val[i] !== str) delete val[i]
41+
}
42+
}
43+
})
44+
})(result)
45+
return result
46+
}
47+
48+
// 2.数组元素分类:写一个函数,将
49+
arr = ['2018年1月1日', '2018年1月5日', '2019年7月17日', '2020年4月19日', '2020年4月30日', '2020年11月25日']
50+
// 转化为:
51+
obj = {
52+
'2018-1': ['2018年1月1日', '2018年1月5日'],
53+
'2019-7': ['2019年7月5日'],
54+
'2020-4': ['2020年4月1日', '2020年4月3日'],
55+
'2020-11': ['2020年11月25日']
56+
}
57+
58+
function change(arr) {
59+
const res = {}, set = new Set();
60+
arr.forEach(element => {
61+
let key;
62+
if (element.charAt(6) === '-') key = element.slice(0, 6);
63+
else key = element.slice(0, 7);
64+
if (!set.has(key)) {
65+
set.add(key);
66+
res[key] = [element];
67+
} else res[key].push(element);
68+
});
69+
return res;
70+
}
71+
change(arr);

‎Topics/合并对象&时间计算.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// 2021秋招-哔哩哔哩笔试
2+
3+
// 1.合并对象:合并 2 个对象以及其子对象,返回一个新的对象,如:
4+
// { a: 1 } { a: 2 },返回 { a: [1,2] }
5+
// { a: 1 } { b: 1 },返回 { a: 1, b: 1 }
6+
// { a: [1] } { a: [2] },返回 { a: [1,2] }
7+
// 如果合并的对象类型不同则 throw error
8+
9+
const obj1 = arr[0], obj2 = arr[1], res = {};
10+
for (const i of Object.entries(obj1)) var key1 = i[0], val1 = i[1];
11+
for (const i of Object.entries(obj2)) var key2 = i[0], val2 = i[1];
12+
if (Object.prototype.toString.call(this, val1) !== Object.prototype.toString.call(this,val2)) throw error;
13+
14+
if (key1 === key2) {
15+
}
16+
17+
// JSON.parse(obj1)
18+
// JSON.stringify(obj1)
19+
20+
console.log(arr)
21+
console.log(JSON.parse(JSON.stringify(obj1)), JSON.parse(JSON.stringify(obj2)))
22+
console.log(key1, val1, key2, val2)
23+
24+
25+
26+
// 2.时间计算:写一个函数接收语义化的描述,得到计算后的日期时间。
27+
// PS: (暂不考虑【月】【年】的计算)
28+
// +/-3W 加或减3周,+/-3d 加或减3天,+/-3h 加或减3小时
29+
// +/-3m 加或减3分钟,+/-3s 加或减3秒
30+
31+
// 2021年09月13日 00:00:00
32+
// +5d
33+
// 得到结果:2021年09月18日 00:00:00
34+
35+
// 2021年09月13日 00:00:00
36+
// +3m +3h
37+
// 得到结果:2021年09月13日 03:03:00
38+
39+
const day = arr[0].split('-'),
40+
time = arr[1].split(':');
41+
42+
for (let i = 2; i < arr.length; i++) {
43+
const str = arr[i];
44+
if (str.endsWith('s')) {
45+
if (str.startsWith('+')) {
46+
47+
}
48+
}
49+
}
50+
console.log(day);

‎Topics/招聘/2021秋招-去哪儿网笔试.js‎ renamed to ‎Topics/大数相加.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
// 大数相加:以字符串的形式读入两个较大的数字,编写一个函数计算它们的和,以字符串形式返回。
44
function solveMeFirst1(number1, number2) {
5-
const longArr=[], shortArr=[];
5+
let longArr, shortArr;
66
if (number1.length > number2.length) {
7-
for(constxofnumber1)longArr.push(x)
8-
for(constyofnumber2)shortArr.push(y)
7+
longArr=Array.from(number1);
8+
shortArr=Array.from(number2);
99
} else {
10-
for(constxofnumber1)shortArr.push(x)
11-
for(constyofnumber2)longArr.push(y)
10+
longArr=Array.from(number2);
11+
shortArr=Array.from(number1);
1212
}
1313

1414
const max = longArr.length, min = shortArr.length;

‎Topics/招聘/2021秋招-小红书笔试.js‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎Topics/招聘/2021秋招-深信服一面.js‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎Topics/排列组合.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// 排列
2+
23
function queue(arr, size) {
34
if (size > arr.length) return;
45
const allResult = [];
@@ -21,6 +22,7 @@ console.log(queue([1, 2, 3], 3)); // A(3, 3) = 3! = 6
2122
console.log(queue([1, 2, 3, 4], 3)); // A(4, 3) = 4! / 1! = 24
2223

2324
// 组合
25+
2426
function choose(arr, size) {
2527
const allResult = [];
2628

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /