-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (27 loc) · 904 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const path = require('path');
const inversNumber = (text) => {
let reversedText = '';
let currentNumber = ''
for(let i = 0; i < text.length; i++) {
const char = text[i];
if(/[0-9]/.test(char)) {
currentNumber += char;
} else {
if(currentNumber !== "") {
const reversedNumber = currentNumber.split('').reverse().join("")
reversedText += reversedNumber;
currentNumber = '';
}
reversedText += char;
}
}
if (currentNumber !== '') {
const reversedNumber = currentNumber.split('').reverse().join('');
reversedText += reversedNumber;
}
return reversedText
}
const input = fs.readFileSync(path.join(__dirname, 'input.txt'), 'utf8');
const output = inversNumber(input)
fs.writeFileSync("output.txt", output)