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 7e6111f

Browse files
committed
update
1 parent 7579d8a commit 7e6111f

6 files changed

+37
-63
lines changed

‎Topics/url获取key的value值&字符串相邻去重.js‎

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

33
// 1.url 获取 key 的 value 值
44
function solveMeFirst1(url, key) {
5-
let s = '&';
6-
if (!url.includes('&')) s = '?';
7-
const arr = url.split(s);
5+
let search = '&';
6+
if (!url.includes(search)) search = '?';
7+
const arr = url.split(search);
88
for (let i = 0; i < arr.length; i++) {
99
if (arr[i].includes(key)) {
1010
const index = arr[i].indexOf(key) + key.length + 1;
@@ -14,18 +14,18 @@ function solveMeFirst1(url, key) {
1414
return false
1515
}
1616

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
17+
console.log(solveMeFirst1('https://xiaohongshu.com?ans=984','ans')); // 984
18+
console.log(solveMeFirst1('https://xiaohongshu.com?name=619&key=88&ans=984','kkk')); // false
19+
console.log(solveMeFirst1('https://xiaohongshu.com?name=619&key=88&ans=984','name')); // 619
2020

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]
21+
// 2.字符串相邻去重
22+
function solveMeFirst2(str) {
23+
let res = '';
24+
for (let i = 0; i < str.length; i++) {
25+
if (str[i] !== str[i + 1]) res += str[i]
2726
}
2827
return res;
2928
}
3029

31-
console.log(solveMeFirst3('AAAABBBCCDAABBB'));
30+
console.log(solveMeFirst3('AAAABBBCCCDDDAABBB')); // ABCDAB
31+
console.log(solveMeFirst3('fewwffffwerreroao')); // fewfwereroao

‎Topics/二维数组组合.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,37 @@
22

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

77
const arr = [['red', 'green'], ['a1', 'a2'], ['b1', 'b2']];
88

99
// 方法一:
10+
function create(arr) {return arr.reduce((a, b) => a.map(aItem => b.map(bItem => aItem + '-' + bItem)).reduce((a, b) => [...a, ...b]))}
11+
1012
function create(arr) {
1113
let res = arr.reduce(
1214
(a, b) => a.map(aItem => b.map(bItem => aItem + '-' + bItem)).reduce((a, b) => [...a, ...b])
1315
);
1416
return res
1517
}
18+
1619
function create(arr) {
1720
let res;
1821
res = arr.reduce(function (a, b) {
1922
let res = a.map(function (aItem) {
2023
let res = b.map(function (bItem) {
2124
console.log(aItem + '-' + bItem)
22-
return aItem + '-' + bItem
25+
return aItem + '-' + bItem;
2326
})
24-
return res
27+
return res;
2528
})
2629
console.log(res)
2730
res = res.reduce(function (a, b) {
28-
return [...a, ...b]
31+
return [...a, ...b];
2932
})
30-
return res
33+
return res;
3134
})
32-
return res
35+
return res;
3336
}
3437

3538
// 方法二:

‎Topics/判断数据类型&直线任务.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ function type(obj) {
77
return res === 'object' ? Object.prototype.toString.call(obj).replace('[object ', '').replace(']', '') : res.replace(res[0], res[0].toUpperCase());
88
}
99

10+
console.log(type(123)); // Number
11+
console.log(type('123')); // String
12+
console.log(type(false)); // Boolean
13+
console.log(type(['123'])); // Array
14+
console.log(type(null)); // Null
15+
1016
// 直线任务:小明在一条直线上执行任务,需要在坐标0的位置和坐标a的位置之间需要从0移动到a,
1117
// 每移动1个单位坐标,小明携带的仪器需要耗费对应1个单位的能量。
1218
// 携带的仪器最多可装b个单位能量,初始时仪器是满能量。坐标0和a之间有一处坐标f的位置

‎Topics/排列组合.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function queue(arr, size) {
1818

1919
return allResult;
2020
}
21+
2122
console.log(queue([1, 2, 3], 3)); // A(3, 3) = 3! = 6
2223
console.log(queue([1, 2, 3, 4], 3)); // A(4, 3) = 4! / 1! = 24
2324

@@ -46,4 +47,5 @@ function choose(arr, size) {
4647

4748
return allResult;
4849
}
50+
4951
console.log(choose([1, 2, 3, 4, 5], 3)); // C(5,3) = A(5,3) / A(3,3) = 10

‎Topics/数字分解.js‎

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

‎Topics/数组去重排序&转驼峰.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ function sortWith(arr) {
1010
})
1111
return arr;
1212
}
13+
1314
sortWith([5, 4, 9, 4, 1, 55, 2]); // [1, 2, 4, 5, 9, 55]
1415

1516
// 转驼峰
1617
function change(str) {
1718
for (let i = 0; i < str.length; i++) {
1819
if (str[i] === '-') {
1920
// 字符串的方法在操作字符串时都不会改变原字符串
20-
str = str.replace(str[i],'');
21+
str = str.replace(str[i],'');
2122
str = str.replace(str[i], str[i].toUpperCase());
2223
}
2324
}
24-
return str
25+
return str;
2526
}
2627

2728
change('a-bcd-ef-gh-i'); // 'aBcdEfGhI'
@@ -35,8 +36,9 @@ function change1(str) {
3536
i++;
3637
}
3738
}
38-
return res
39+
return res;
3940
}
41+
4042
change1('a-bcd-ef-gh-i'); // 'aBcdEfGhI'
4143

4244
function change2(str) {
@@ -49,6 +51,7 @@ function change2(str) {
4951
}
5052
return arr.join('');
5153
}
54+
5255
change2('a-bcd-ef-gh-i'); // 'aBcdEfGhI'
5356

5457
// 九九乘法口诀表
@@ -62,4 +65,5 @@ function print99() {
6265
console.log(...resArr);
6366
}
6467
}
68+
6569
print99();

0 commit comments

Comments
(0)

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