Skip to content

Commit 5a14982

Browse files
committed
update: --
1 parent 4224cf2 commit 5a14982

12 files changed

+431
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ https://github.com/webVueBlog/Leetcode
1313

1414
欢迎大家前来讨论,如果觉得对你的学习有一定的帮助,欢迎点个Star (此仓库每天都会准时更新)
1515

16-
## 😘 阶段十三(361
16+
## 😘 阶段十三(370
1717

1818
<details open>
1919
<summary>展开查看</summary>
@@ -39,6 +39,16 @@ https://github.com/webVueBlog/Leetcode
3939
- 359.[Boolean](./阶段十三/Boolean.js)
4040
- 360.[Number](./阶段十三/Number.js)
4141
- 361.[String](./阶段十三/String.js)
42+
- 362.[字符串操作方法](./阶段十三/字符串操作方法.js)
43+
- 363.[字符串包含方法](./阶段十三/字符串包含方法.js)
44+
- 364.[trim](./阶段十三/trim.js)
45+
- 365.[repeat](./阶段十三/repeat.js)
46+
- 366.[padStart()和 padEnd()方法](./阶段十三/方法.js)
47+
- 367.[字符串迭代与解构](./阶段十三/字符串迭代与解构.js)
48+
- 368.[字符串模式匹配方法](./阶段十三/字符串模式匹配方法.js)
49+
- 369.[localeCompare()方法](./阶段十三/localeCompare.js)
50+
- 370.[ HTML 方法](./阶段十三/HTML.js)
51+
4252

4353
</details>
4454

@@ -64,6 +74,8 @@ https://github.com/webVueBlog/Leetcode
6474
- 338.[传递参数](./阶段十二/传递参数.js)
6575
- 339.[typeof 操作符](./阶段十二/确定类型.js)
6676
- 340.[执行上下文与作用域](./阶段十二/执行上下文与作用域.js)
77+
- 341.[Global](./阶段十二/Global.js)
78+
- 342.[Math](./阶段十二/Math.js)
6779

6880
</details>
6981

阶段十三/Global.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
*
3+
在全局作用域中定义的变量和函数都会变成 Global 对象的属性 。
4+
5+
isNaN()、isFinite()、parseInt()和 parseFloat(),实际上都是 Global 对象的方法。
6+
7+
1. URL 编码方法
8+
9+
encodeURI()和 encodeURIComponent()方法用于编码统一资源标识符(URI),以便传给浏览器。
10+
11+
ecnodeURI()方法用于对整个 URI 进行编码
12+
13+
encodeURIComponent()方法用于编码 URI 中单独的组件
14+
15+
这两个方法的主要区别是,encodeURI()不会编码属于 URL 组件的特殊字符,比如冒号、斜杠、问号、井号,而 encodeURIComponent()会编码它发现的所有非标准字符。来
16+
17+
18+
let uri = "http://www.wrox.com/illegal value.js#start";
19+
// "http://www.wrox.com/illegal%20value.js#start"
20+
console.log(encodeURI(uri));
21+
// "http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.js%23start"
22+
console.log(encodeURIComponent(uri));
23+
VM1436:3 http://www.wrox.com/illegal%20value.js#start
24+
VM1436:5 http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.js%23start
25+
26+
与 encodeURI()和 encodeURIComponent()相对的是 decodeURI()和 decodeURIComponent()。decodeURI()只对使用 encodeURI()编码过的字符解码。例如,%20 会被替换为空格,但%23 不会被替换为井号(#),因为井号不是由 encodeURI()替换的。类似地,decodeURIComponent()解码所有被 encodeURIComponent()编码的字符,基本上就是解码所有特殊值。
27+
28+
29+
let uri = "http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.js%23start";
30+
// http%3A%2F%2Fwww.wrox.com%2Fillegal value.js%23start
31+
console.log(decodeURI(uri));
32+
// http:// www.wrox.com/illegal value.js#start
33+
console.log(decodeURIComponent(uri));
34+
35+
36+
window 对象
37+
38+
var color = "red";
39+
function sayColor() {
40+
console.log(window.color);
41+
}
42+
window.sayColor(); // "red"
43+
44+
45+
Global 对象属性
46+
47+
undefined 特殊值 undefined
48+
NaN 特殊值 NaN
49+
Infinity 特殊值 Infinity
50+
Object Object 的构造函数
51+
Array Array 的构造函数
52+
Function Function 的构造函数
53+
Boolean Boolean 的构造函数
54+
String String 的构造函数
55+
56+
Number Number 的构造函数
57+
Date Date 的构造函数
58+
RegExp RegExp 的构造函数
59+
Symbol Symbol 的伪构造函数
60+
Error Error 的构造函数
61+
EvalError EvalError 的构造函数
62+
RangeError RangeError 的构造函数
63+
ReferenceError ReferenceError 的构造函数
64+
SyntaxError SyntaxError 的构造函数
65+
TypeError TypeError 的构造函数
66+
URIError URIError 的构造函数
67+
68+
69+
eval()方法
70+
71+
72+
这个方法就是一个完整的 ECMAScript 解释器
73+
74+
eval("console.log('hi')");
75+
76+
console.log("hi");
77+
78+
let msg = "hello world";
79+
eval("console.log(msg)"); // "hello world"
80+
81+
eval("let msg = 'hello world';");
82+
console.log(msg); // Reference Error: msg is not defined
83+
84+
通过 eval()定义的任何变量和函数都不会被提升,这是因为在解析代码的时候,它们是被包含在一个字符串中的。它们只是在 eval()执行的时候才会被创建。
85+
86+
*/

阶段十三/HTML.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
3+
anchor(name) <a name="name">string</a>
4+
big() <big>string</big>
5+
bold() <b>string</b>
6+
fixed() <tt>string</tt>
7+
fontcolor(color) <font color="color">string</font>
8+
fontsize(size) <font size="size">string</font>
9+
italics() <i>string</i>
10+
link(url) <a href="url">string</a>
11+
small() <small>string</small>
12+
strike() <strike>string</strike>
13+
sub() <sub>string</sub>
14+
sup() <sup>string</sup>
15+
16+
*/

阶段十三/Math.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
*
3+
4+
1. Math 对象属性
5+
6+
Math.E 自然对数的基数 e 的值
7+
Math.LN10 10 为底的自然对数
8+
Math.LN2 2 为底的自然对数
9+
Math.LOG2E 以 2 为底 e 的对数
10+
Math.LOG10E 以 10 为底 e 的对数
11+
Math.PI π 的值
12+
Math.SQRT1_2 1/2 的平方根
13+
Math.SQRT2 2 的平方根
14+
15+
2. min()和 max()方法
16+
17+
3. 舍入方法
18+
Math.ceil()方法始终向上舍入为最接近的整数。
19+
Math.floor()方法始终向下舍入为最接近的整数
20+
Math.round()方法执行四舍五入。
21+
Math.fround()方法返回数值最接近的单精度(32 位)浮点值表示。
22+
23+
console.log(Math.ceil(25.9)); // 26
24+
console.log(Math.ceil(25.5)); // 26
25+
console.log(Math.ceil(25.1)); // 26
26+
console.log(Math.round(25.9)); // 26
27+
console.log(Math.round(25.5)); // 26
28+
console.log(Math.round(25.1)); // 25
29+
console.log(Math.fround(0.4)); // 0.4000000059604645
30+
console.log(Math.fround(0.5)); // 0.5
31+
console.log(Math.fround(25.9)); // 25.899999618530273
32+
console.log(Math.floor(25.9)); // 25
33+
console.log(Math.floor(25.5)); // 25
34+
console.log(Math.floor(25.1)); // 25
35+
36+
4. random()方法
37+
Math.random()方法返回一个 0~1 范围内的随机数,其中包含 0 但不包含 1。
38+
39+
Math.abs(x) 返回 x 的绝对值
40+
Math.exp(x) 返回 Math.E 的 x 次幂
41+
Math.expm1(x) 等于 Math.exp(x) - 1
42+
Math.log(x) 返回 x 的自然对数
43+
Math.log1p(x) 等于 1 + Math.log(x)
44+
Math.pow(x, power) 返回 x 的 power 次幂
45+
Math.hypot(...nums) 返回 nums 中每个数平方和的平方根
46+
Math.clz32(x) 返回 32 位整数 x 的前置零的数量
47+
Math.sign(x) 返回表示 x 符号的 1、0、-0 或-1
48+
Math.trunc(x) 返回 x 的整数部分,删除所有小数
49+
Math.sqrt(x) 返回 x 的平方根
50+
Math.cbrt(x) 返回 x 的立方根
51+
Math.acos(x) 返回 x 的反余弦
52+
Math.acosh(x) 返回 x 的反双曲余弦
53+
Math.asin(x) 返回 x 的反正弦
54+
Math.asinh(x) 返回 x 的反双曲正弦
55+
Math.atan(x) 返回 x 的反正切
56+
Math.atanh(x) 返回 x 的反双曲正切
57+
Math.atan2(y, x) 返回 y/x 的反正切
58+
Math.cos(x) 返回 x 的余弦
59+
Math.sin(x) 返回 x 的正弦
60+
Math.tan(x) 返回 x 的正切
61+
62+
63+
*/

阶段十三/localeCompare.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
3+
localeCompare(),这个方法比较两个字符串
4+
5+
如果按照字母表顺序,字符串应该排在字符串参数前头,则返回负值。
6+
7+
如果字符串与字符串参数相等,则返回 0。
8+
9+
如果按照字母表顺序,字符串应该排在字符串参数后头,则返回正值。
10+
11+
let stringValue = "yellow";
12+
console.log(stringValue.localeCompare("brick")); // 1
13+
console.log(stringValue.localeCompare("yellow")); // 0
14+
console.log(stringValue.localeCompare("zoo")); // -1
15+
16+
*/

阶段十三/repeat.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
3+
ECMAScript 在所有字符串上都提供了 repeat()方法。这个方法接收一个整数参数,表示要将字
4+
符串复制多少次,然后返回拼接所有副本后的结果。
5+
6+
let stringValue = "na ";
7+
console.log(stringValue.repeat(16) + "batman");
8+
// na na na na na na na na na na na na na na na na batman
9+
10+
*/

阶段十三/trim.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
3+
ECMAScript 在所有字符串上都提供了 trim()方法
4+
5+
let stringValue = " hello world ";
6+
let trimmedStringValue = stringValue.trim();
7+
console.log(stringValue); // " hello world "
8+
console.log(trimmedStringValue); // "hello world"
9+
10+
trim()返回的是字符串的副本
11+
12+
trimLeft()和 trimRight()方法分别用于从字符串开始和末尾清理空格符。
13+
14+
*/

阶段十三/字符串包含方法.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
3+
ECMAScript 6 增加了 3 个用于判断字符串中是否包含另一个字符串的方法:startsWith()、endsWith()和 includes()。
4+
5+
返回一个表示是否包含的布尔值。
6+
7+
startsWith()检查开始于索引 0 的匹配项,endsWith()检查开始于索引(string.length - substring.length)的匹配项,而 includes()检查整个字符串
8+
9+
let message = "foobarbaz";
10+
console.log(message.startsWith("foo")); // true
11+
console.log(message.startsWith("bar")); // false
12+
console.log(message.endsWith("baz")); // true
13+
console.log(message.endsWith("bar")); // false
14+
console.log(message.includes("bar")); // true
15+
console.log(message.includes("qux")); // false
16+
17+
18+
startsWith()和 includes()方法接收可选的第二个参数,表示开始搜索的位置。
19+
20+
let message = "foobarbaz";
21+
console.log(message.startsWith("foo")); // true
22+
console.log(message.startsWith("foo", 1)); // false
23+
console.log(message.includes("bar")); // true
24+
console.log(message.includes("bar", 4)); // false
25+
26+
27+
let message = "foobarbaz";
28+
console.log(message.endsWith("bar")); // false
29+
console.log(message.endsWith("bar", 6)); // true
30+
31+
32+
*/

阶段十三/字符串操作方法.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
3+
concat(),用于将一个或多个字符串拼接成一个新字
4+
5+
let stringValue = "hello ";
6+
let result = stringValue.concat("world");
7+
console.log(result); // "hello world"
8+
console.log(stringValue); // "hello"
9+
10+
concat()方法可以接收任意多个参数,因此可以一次性拼接多个字符串
11+
12+
更常用的方式是使用加号操作符(+)
13+
14+
15+
3 个从字符串中提取子字符串的方法:slice()、substr()和 substring()
16+
17+
第一个参数表示子字符串开始的位置,第二个参数表示子字符串结束的位置。
18+
19+
slice() substring()
20+
对 slice()和 substring()而言,第二个参数是提取结束的位置(即该位置之前的字符会被提取出来)。
21+
22+
substr()而言
23+
第二个参数表示返回的子字符串数量。
24+
25+
let stringValue = "hello world";
26+
console.log(stringValue.slice(3)); // "lo world"
27+
console.log(stringValue.substring(3)); // "lo world"
28+
console.log(stringValue.substr(3)); // "lo world"
29+
console.log(stringValue.slice(3, 7)); // "lo w"
30+
console.log(stringValue.substring(3,7)); // "lo w"
31+
console.log(stringValue.substr(3, 7)); // "lo worl"
32+
33+
slice()方法将所有负值参数都当成字符串长度加上负参数值。
34+
35+
substring()方法会将所有负参数值都转换为 0
36+
37+
substr()方法将第一个负参数值当成字符串长度加上该值,将第二个负参数值转换为 0。
38+
39+
let stringValue = "hello world";
40+
console.log(stringValue.slice(-3)); // "rld"
41+
console.log(stringValue.substring(-3)); // "hello world"
42+
console.log(stringValue.substr(-3)); // "rld"
43+
console.log(stringValue.slice(3, -4)); // "lo w"
44+
console.log(stringValue.substring(3, -4)); // "hel"
45+
console.log(stringValue.substr(3, -4)); // "" (empty string)
46+
47+
substring(3, 0),等价于 substring(0, 3)
48+
49+
50+
字符串位置方法
51+
52+
indexOf()和 lastIndexOf()
53+
54+
indexOf()方法从字符串开头开始查找子字符串,而 lastIndexOf()方法从字符串末尾开始查找子字符串。
55+
56+
let stringValue = "hello world";
57+
console.log(stringValue.indexOf("o")); // 4
58+
console.log(stringValue.lastIndexOf("o")); // 7
59+
60+
这两个方法都可以接收可选的第二个参数,表示开始搜索的位置。
61+
62+
indexOf()会从这个参数指定的位置开始向字符串末尾搜索,忽略该位置之前的字符;lastIndexOf()则会从这个参数指定的位置开始向字符串开头搜索,忽略该位置之后直到字符串末尾的字符。
63+
64+
*/

0 commit comments

Comments
 (0)