From 2c3f4c3199149ac38ea4a9b5cc7ab919579bf5a2 Mon Sep 17 00:00:00 2001 From: Yuanyuan Yang <1005842457@qq.com> Date: Mon, 29 Jan 2024 17:08:00 -0500 Subject: [PATCH 1/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3a32bc2..ec9422d0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # learn-js JavaScript tutorial repo -### REPLACE WITH YOUR FULL NAME +### Yuanyuan Yang From 7911b46705d4b09a841545f27a7476736d745d42 Mon Sep 17 00:00:00 2001 From: Yuanyuan Yang <1005842457@qq.com> Date: Fri, 9 Feb 2024 15:16:21 -0500 Subject: [PATCH 2/4] Update map-deep.js --- quiz/scripts/map-deep.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quiz/scripts/map-deep.js b/quiz/scripts/map-deep.js index e97665e5..8635a723 100644 --- a/quiz/scripts/map-deep.js +++ b/quiz/scripts/map-deep.js @@ -6,7 +6,7 @@ const originalMatrix = [ ]; const newMatrix = originalMatrix.map((row) => { - return row.sort(); + return [...row].sort((a, b) => a - b); }); // Modifying the original matrix (changing the last element of the first row) @@ -15,4 +15,4 @@ const originalMatrix = [ // Displaying the original and new matrices console.log('Original Matrix (modified):', originalMatrix); console.log('New Matrix (unaffected):', newMatrix); - \ No newline at end of file + From c3ccee9df8ecc8c8051038952b38508e9c26d83f Mon Sep 17 00:00:00 2001 From: Yuanyuan Yang <1005842457@qq.com> Date: Fri, 9 Feb 2024 15:19:51 -0500 Subject: [PATCH 3/4] Update exception.html --- quiz/exception.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/quiz/exception.html b/quiz/exception.html index c154b213..a01e0d2c 100644 --- a/quiz/exception.html +++ b/quiz/exception.html @@ -24,8 +24,16 @@

Error Handling with Array Map

// Using map to calculate the square root of each number // Use Math.sqrt(number) to calculate sq root const squareRoots = numbers.map(number => { - return 0 - }); + try { + if (number < 0) { + throw new Error(`Cannot calculate square root of negative number: ${number}`); + } + return Math.sqrt(number); + } catch (error) { + console.error(error.message); + return NaN; + } + }); // Displaying the original and transformed arrays console.log('Original Numbers Array:', numbers); From ec8ba7e24e13724b9c949e02b0d4b22c1b92f404 Mon Sep 17 00:00:00 2001 From: Yuanyuan Yang <1005842457@qq.com> Date: Fri, 9 Feb 2024 15:26:21 -0500 Subject: [PATCH 4/4] Update stack-q1.js --- quiz/scripts/stack-q1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/quiz/scripts/stack-q1.js b/quiz/scripts/stack-q1.js index 0d719223..40fd495e 100644 --- a/quiz/scripts/stack-q1.js +++ b/quiz/scripts/stack-q1.js @@ -9,6 +9,14 @@ class PStack { return this.#id; } + get persons() { + return this._persons.slice(); + } + + addPerson(person) { + this._persons.push(person); + } + } class PStackImpl extends PStack { @@ -21,6 +29,10 @@ class PStackImpl extends PStack { } pop() { + if (this.persons.length === 0) { + console.error('No persons to pop.'); + return NaN; + } return this._persons.pop().age } }