Skip to content

Commit 090d5f5

Browse files
committed
Add solution #1556
1 parent a6eedae commit 090d5f5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,364 LeetCode solutions in JavaScript
1+
# 1,365 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1187,6 +1187,7 @@
11871187
1551|[Minimum Operations to Make Array Equal](./solutions/1551-minimum-operations-to-make-array-equal.js)|Medium|
11881188
1552|[Magnetic Force Between Two Balls](./solutions/1552-magnetic-force-between-two-balls.js)|Medium|
11891189
1553|[Minimum Number of Days to Eat N Oranges](./solutions/1553-minimum-number-of-days-to-eat-n-oranges.js)|Hard|
1190+
1556|[Thousand Separator](./solutions/1556-thousand-separator.js)|Easy|
11901191
1566|[Detect Pattern of Length M Repeated K or More Times](./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js)|Easy|
11911192
1576|[Replace All ?'s to Avoid Consecutive Repeating Characters](./solutions/1576-replace-all-s-to-avoid-consecutive-repeating-characters.js)|Medium|
11921193
1598|[Crawler Log Folder](./solutions/1598-crawler-log-folder.js)|Easy|

solutions/1556-thousand-separator.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 1556. Thousand Separator
3+
* https://leetcode.com/problems/thousand-separator/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer n, add a dot (".") as the thousands separator and return it in string format.
7+
*/
8+
9+
/**
10+
* @param {number} n
11+
* @return {string}
12+
*/
13+
var thousandSeparator = function(n) {
14+
const digits = n.toString().split('');
15+
const result = [];
16+
17+
while (digits.length > 0) {
18+
const group = digits.splice(-3).join('');
19+
result.unshift(group);
20+
if (digits.length > 0) {
21+
result.unshift('.');
22+
}
23+
}
24+
25+
return result.join('');
26+
};

0 commit comments

Comments
 (0)