Skip to content

Commit 4fc8190

Browse files
committed
https://leetcode.cn/problems/thousand-separator/
1 parent ba2849b commit 4fc8190

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/thousand-separator/
14+
1315
https://leetcode.cn/problems/count-odd-numbers-in-an-interval-range/
1416

1517
https://leetcode.cn/problems/shuffle-string/

thousand-separator/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function thousandSeparator(n: number): string {
2+
const str = [...n.toString()].reverse();
3+
return Array(Math.ceil(str.length / 3)).fill(0).map((_, i) =>
4+
str.slice(i * 3, i * 3 + 3).reverse().join("")
5+
).reverse().join(".");
6+
}

0 commit comments

Comments
 (0)