From c1bf6ab53f0065af09ee7cd090779ba5c9ad0828 Mon Sep 17 00:00:00 2001 From: AlessandroVerzella <116301354+AlessandroVerzella@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:10:56 +0200 Subject: [PATCH 1/5] added a console.log instruction --- projects/m1/001-area-of-a-room/js/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/m1/001-area-of-a-room/js/index.js b/projects/m1/001-area-of-a-room/js/index.js index e69de29bb..66c7ece20 100644 --- a/projects/m1/001-area-of-a-room/js/index.js +++ b/projects/m1/001-area-of-a-room/js/index.js @@ -0,0 +1 @@ +console.log('aaa'); From 66f5b5d19e2ea09f38877109b2d91f2719ce10de Mon Sep 17 00:00:00 2001 From: AlessandroVerzella <116301354+AlessandroVerzella@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:13:16 +0200 Subject: [PATCH 2/5] add a second console log --- projects/m1/001-area-of-a-room/js/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/m1/001-area-of-a-room/js/index.js b/projects/m1/001-area-of-a-room/js/index.js index 66c7ece20..a1be9412c 100644 --- a/projects/m1/001-area-of-a-room/js/index.js +++ b/projects/m1/001-area-of-a-room/js/index.js @@ -1 +1,3 @@ console.log('aaa'); + +console.log('bbb'); From fb2e8d5b625f99798a1c151b734e3fd13e101d59 Mon Sep 17 00:00:00 2001 From: AlessandroVerzella <116301354+AlessandroVerzella@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:15:02 +0200 Subject: [PATCH 3/5] removed console.logs --- projects/m1/001-area-of-a-room/js/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/projects/m1/001-area-of-a-room/js/index.js b/projects/m1/001-area-of-a-room/js/index.js index a1be9412c..e69de29bb 100644 --- a/projects/m1/001-area-of-a-room/js/index.js +++ b/projects/m1/001-area-of-a-room/js/index.js @@ -1,3 +0,0 @@ -console.log('aaa'); - -console.log('bbb'); From 96833a6025ecad5a83f6940df928ba6e7061122f Mon Sep 17 00:00:00 2001 From: AlessandroVerzella Date: Fri, 4 Oct 2024 17:07:28 +0200 Subject: [PATCH 4/5] Added the solution of the exercise --- .../js/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/projects/m4/001-display-the-head-of-a-file/js/index.js b/projects/m4/001-display-the-head-of-a-file/js/index.js index e69de29bb..f439d1909 100644 --- a/projects/m4/001-display-the-head-of-a-file/js/index.js +++ b/projects/m4/001-display-the-head-of-a-file/js/index.js @@ -0,0 +1,19 @@ +const { readFile } = require('fs/promises'); + +let filePath1 = './example1.txt'; +let filePath2 = './example2.txt'; + +readFile(filePath1).then((data1) => { + console.log(data1.toString().split('\r\n').slice(-11).join('\r\n')); + console.log(data1.toString().split('\r\n').slice(-6).join('\r\n')); + console.log(data1.toString().split('\r\n').slice(-6, -3).join('\r\n')); +}); + +Promise.all([readFile(filePath1), readFile(filePath2)]) + .then(([data1, data2]) => { + console.log(data1.toString().split('\r\n').slice(-2).join('\r\n')); + console.log(data2.toString().split('\r\n').slice(-2).join('\r\n')); + }) + .catch((error) => { + console.log(error); + }); From e437568af53b6f5e68669403777cbe4e4f1a1664 Mon Sep 17 00:00:00 2001 From: AlessandroVerzella Date: Fri, 4 Oct 2024 17:12:11 +0200 Subject: [PATCH 5/5] Added the solution of the exercise --- .../js/example1.txt | 24 ++++++++++++++++++ .../js/example2.txt | 25 +++++++++++++++++++ .../js/index.js | 19 ++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 projects/m4/002-display-the-tail-of-a-file/js/example1.txt create mode 100644 projects/m4/002-display-the-tail-of-a-file/js/example2.txt diff --git a/projects/m4/002-display-the-tail-of-a-file/js/example1.txt b/projects/m4/002-display-the-tail-of-a-file/js/example1.txt new file mode 100644 index 000000000..fbc36b634 --- /dev/null +++ b/projects/m4/002-display-the-tail-of-a-file/js/example1.txt @@ -0,0 +1,24 @@ +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. +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. +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. +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/002-display-the-tail-of-a-file/js/example2.txt b/projects/m4/002-display-the-tail-of-a-file/js/example2.txt new file mode 100644 index 000000000..6d7503b48 --- /dev/null +++ b/projects/m4/002-display-the-tail-of-a-file/js/example2.txt @@ -0,0 +1,25 @@ +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. +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. +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. +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. +Line 25: This is the twenty-fifth line. diff --git a/projects/m4/002-display-the-tail-of-a-file/js/index.js b/projects/m4/002-display-the-tail-of-a-file/js/index.js index e69de29bb..f439d1909 100644 --- a/projects/m4/002-display-the-tail-of-a-file/js/index.js +++ b/projects/m4/002-display-the-tail-of-a-file/js/index.js @@ -0,0 +1,19 @@ +const { readFile } = require('fs/promises'); + +let filePath1 = './example1.txt'; +let filePath2 = './example2.txt'; + +readFile(filePath1).then((data1) => { + console.log(data1.toString().split('\r\n').slice(-11).join('\r\n')); + console.log(data1.toString().split('\r\n').slice(-6).join('\r\n')); + console.log(data1.toString().split('\r\n').slice(-6, -3).join('\r\n')); +}); + +Promise.all([readFile(filePath1), readFile(filePath2)]) + .then(([data1, data2]) => { + console.log(data1.toString().split('\r\n').slice(-2).join('\r\n')); + console.log(data2.toString().split('\r\n').slice(-2).join('\r\n')); + }) + .catch((error) => { + console.log(error); + });