1 parent 5a32261 commit 2b8e636Copy full SHA for 2b8e636
1 file changed
common.md
@@ -16,3 +16,30 @@ function maxInArray(arr) {
16
return Math.max.apply(Math, arr);
17
}
18
```
19
+
20
+### 3. 字符串反转
21
22
+```js
23
+String.prototype.reverse = function() {
24
+ return this.split('').reverse().join('');
25
+}
26
+```
27
+or
28
29
30
31
+ var str = '';
32
+ var len = this.length;
33
+ while (len>0) {
34
+ str += this.substring(len-1, len);
35
+ len--;
36
+ }
37
+ return str;
38
39
40
41
+注: 在类似'foo 𝌆 bar'这种astral symbol,将展示异。
42
43
+可以使用[ Esrever](https://github.com/mathiasbynens/esrever) 来处理这种特殊字符的反转。
44
45
+### 4.反转DOM
0 commit comments