Skip to content

Commit 2b8e636

Browse files
committed
String reverse
1 parent 5a32261 commit 2b8e636

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

common.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,30 @@ function maxInArray(arr) {
1616
return Math.max.apply(Math, arr);
1717
}
1818
```
19+
20+
### 3. 字符串反转
21+
22+
```js
23+
String.prototype.reverse = function() {
24+
return this.split('').reverse().join('');
25+
}
26+
```
27+
or
28+
29+
```js
30+
String.prototype.reverse = function() {
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

Comments
 (0)