We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6f47d4e commit 4ee0bdfCopy full SHA for 4ee0bdf
scripts/algorithms/T/Thousand Separator/Thousand Separator.js
@@ -1,18 +1,19 @@
1
+// Runtime: 63 ms (Top 94.17%) | Memory: 41.7 MB (Top 95.00%)
2
var thousandSeparator = function(n) {
3
let ans = "";
-
4
+
5
if(n >= 1000){
6
const arr = String(n).split('');
7
for(let i=0;i<arr.length;i++){
8
let temp = arr.length - i;
- if(temp === 3 && arr.length > temp || temp === 6 && arr.length > temp || temp === 9 && arr.length > temp || temp === 12 && arr.length > temp){
9
+ if(temp === 3 && arr.length > temp || temp === 6 && arr.length > temp || temp === 9 && arr.length > temp || temp === 12 && arr.length > temp){
10
ans += '.';
11
}
12
ans += arr[i];
13
14
}else{
15
ans += n;
16
17
18
return ans;
-};
19
+};
0 commit comments