File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,364 LeetCode solutions in JavaScript
1
+ # 1,365 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1187
1187
1551|[ Minimum Operations to Make Array Equal] ( ./solutions/1551-minimum-operations-to-make-array-equal.js ) |Medium|
1188
1188
1552|[ Magnetic Force Between Two Balls] ( ./solutions/1552-magnetic-force-between-two-balls.js ) |Medium|
1189
1189
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|
1190
1191
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|
1191
1192
1576|[ Replace All ?'s to Avoid Consecutive Repeating Characters] ( ./solutions/1576-replace-all-s-to-avoid-consecutive-repeating-characters.js ) |Medium|
1192
1193
1598|[ Crawler Log Folder] ( ./solutions/1598-crawler-log-folder.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments