diff --git a/projects/m4/003-concatenate-multiple-files/js/example1.txt b/projects/m4/003-concatenate-multiple-files/js/example1.txt new file mode 100644 index 000000000..f894de28b --- /dev/null +++ b/projects/m4/003-concatenate-multiple-files/js/example1.txt @@ -0,0 +1,6 @@ +Line 1: This is the first line. +Line 2: This is the second line. +Line 3: This is the third line. +Line 4: This is the fourth line. +Line 5: This is the fifth line. +Line 6: This is the sixth line. \ No newline at end of file diff --git a/projects/m4/003-concatenate-multiple-files/js/example2.txt b/projects/m4/003-concatenate-multiple-files/js/example2.txt new file mode 100644 index 000000000..297045564 --- /dev/null +++ b/projects/m4/003-concatenate-multiple-files/js/example2.txt @@ -0,0 +1,6 @@ +Line 7: This is the seventh line. +Line 8: This is the eighth line. +Line 9: This is the ninth line. +Line 10: This is the tenth line. +Line 11: This is the eleventh line. +Line 12: This is the twelfth line. \ No newline at end of file diff --git a/projects/m4/003-concatenate-multiple-files/js/example3.txt b/projects/m4/003-concatenate-multiple-files/js/example3.txt new file mode 100644 index 000000000..70fefbb94 --- /dev/null +++ b/projects/m4/003-concatenate-multiple-files/js/example3.txt @@ -0,0 +1,6 @@ +Line 13: This is the thirteenth line. +Line 14: This is the fourteenth line. +Line 15: This is the fifteenth line. +Line 16: This is the sixteenth line. +Line 17: This is the seventeenth line. +Line 18: This is the eighteenth line. diff --git a/projects/m4/003-concatenate-multiple-files/js/example4.txt b/projects/m4/003-concatenate-multiple-files/js/example4.txt new file mode 100644 index 000000000..d546eef9f --- /dev/null +++ b/projects/m4/003-concatenate-multiple-files/js/example4.txt @@ -0,0 +1,6 @@ +Line 19: This is the nineteenth line. +Line 20: This is the twentieth line. +Line 21: This is the twenty-first line. +Line 22: This is the twenty-second line. +Line 23: This is the twenty-third line. +Line 24: This is the twenty-fourth line. \ No newline at end of file diff --git a/projects/m4/003-concatenate-multiple-files/js/index.js b/projects/m4/003-concatenate-multiple-files/js/index.js index e69de29bb..5496ce1dc 100644 --- a/projects/m4/003-concatenate-multiple-files/js/index.js +++ b/projects/m4/003-concatenate-multiple-files/js/index.js @@ -0,0 +1,26 @@ +const { readFile } = require('fs/promises'); + +let filePath1 = './example1.txt'; +let filePath2 = './example2.txt'; +let filePath3 = './example3.txt'; +let filePath4 = './example4.txt'; + +Promise.all([ + readFile(filePath1), + readFile(filePath2), + readFile(filePath3), + readFile(filePath4), +]) + .then((data1, data2, data3, data4) => { + console.log( + data1 + .toString() + .split('\r\n') + .concat(data2, data3, data4) + .join('\r\n') + ); + }) + .catch((error) => { + console.log(`Il file non può essere visualizzato`); + console.error(error); + });