|
@@ -35,9 +35,21 @@ function App() {
|
|
|
|
|
|
let numbersArr = numbers.map(x => x.toString().split(""))
|
|
|
for (let numArr of numbersArr){
|
|
|
- while (numArr.indexOf(".")>-1 && numArr.indexOf(".")!==befComma){
|
|
|
+ let commaIdx = numArr.indexOf(".")
|
|
|
+
|
|
|
+ // without comma, add before
|
|
|
+ while(commaIdx===-1 && numArr.length < befComma){
|
|
|
+ numArr.unshift(" "); // add " " before comma
|
|
|
+ }
|
|
|
+ // without comma, add after
|
|
|
+ while(commaIdx===-1 && numArr.length < arrLength){
|
|
|
+ numArr.push(" "); // add " " after comma
|
|
|
+ }
|
|
|
+ // with comma, add before
|
|
|
+ while (commaIdx>-1 && commaIdx!==befComma){
|
|
|
numArr.unshift(" "); // add " " before comma
|
|
|
}
|
|
|
+ // with comma, add after
|
|
|
while (numArr.length < arrLength){
|
|
|
numArr.push(" "); // add " " after comma
|
|
|
}
|