There is something wrong with my code
challenge1 = () => {
var data = fs.readFileSync('santa21.txt', 'utf8');
data = data.toString();
dataSplit = data.split(' ')
console.log(dataSplit);
};
challenge1();
The result of the dataSplit array
[
'1973\r\n' +
'1755\r\n' +
'1601\r\n' +
'1852\r\n' +
'493\r\n' +
'1905\r\n' +
'1752\r\n' +
'1946\r\n' +
'1608\r\n' +
'1438\r\n' +
'1383\r\n' +
'1281\r\n' +
'1918\r\n' +
'1125\r\n' +
'1624\r\n' +
'1802\r\n' +
'1513\r\n' +
'1574\r\n' +
'1871\r\n' +
'1831\r\n' +
'1842\r\n' +
'1869\r\n' +
'1982\r\n' +
'1027\r\n' +
....]
I managed to resolve it by using:
challenge1 = () => {
var data = fs.readFileSync('santa21.txt', 'utf8');
data = data.toString();
dataSplit = data.split('\r\n')
console.log(dataSplit);
};
This is the content of "santa21.txt" file: santa21.txt
1973 1755 1601 1852 493 1905 1752 1946 1608 1438 1383 1281 1918 1125 1624 1802 1513 1574 1871 1831 1842 1869 1982 1027 1009 1020 1016 1336 1519 1721 1960 1889 1299 1355 1622 399 1919 1749 1709 1425 1789 1620 1071 1248 1786 1879 1208 1697 1643 1510 1578 1152 1592 1985 1653 1112 591 1784 1393 1607 1130 1054 1120 1619 1029 1453 1850 1451 1753 1483 1021 1553 1561 1656 1975 1600 1677 1912 1334 1526 1345 1115 2010 1758 1664 1102 1588 1339 1745 1605 1638 1599 1741 1147 1837 1142 1774 1562 1936 1810 1648 1576 1794 1621 1194 1246 1727 1915 1793 1037 1587 1103 1947 1116 1567 1528 1964 1163 1980 1672 1773 1593 1586 169 1613 1712 1854 1632 1760 1182 1812 1811 1660 1728 1067 1835 1501 1335 1647 1853 543 1108 1024 1559 1717 1826 1544 1585 1655 1386 1331 1485 1537 1290 1941 1734 2003 1151 1679 1782 1783 1146 1277 1766 1900 530 1955 1268 1968 1432 1170 1867 1005 1202 1564 1096 1707 1309 1094 1295 1974 1404 1229 1883 1838 1997 1536 408 1149 1945 1454 1856 1792 1614 1492 1823 1803 1533 1726 1364
This issue was encountered while working on a challenge from Advent of Code, and I am trying to understand why there are extra \r and \n characters in the output.