From a8766869697132e039696992714b7481688cebc5 Mon Sep 17 00:00:00 2001 From: demin Date: Thu, 18 Aug 2022 15:50:20 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/add.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/add.js b/lib/add.js index 1714b95..c69f4a4 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,5 +1,34 @@ -function add() { +function add(num1, num2) { // 实现该函数 + let aNum1 = num1.split("").reverse(); + let aNum2 = num2.split("").reverse(); + let maxANum, minANum; + if (aNum1.length > aNum2.length) { + maxANum = aNum1; + minANum = aNum2; + } else { + maxANum = aNum2; + minANum = aNum1; + } + // 进位标识 + let minLen = minANum.length; + let flag = 0; + for (let i = 0; i < minLen; i++) { + let sum = +maxANum[i] + +minANum[i] + flag; + + maxANum[i] = sum % 10; + flag = parseInt(sum / 10); + } + if (flag == 1) { + minLen++; + if (maxANum[minLen]) { + maxANum[minLen]++; + } else { + maxANum[minLen] = 1; + } + } + + return maxANum.reverse().join(""); } -module.exports = add \ No newline at end of file +module.exports = add; From 6022bc3ddc65b330eaa429d5e2d2d3ab3b645ff6 Mon Sep 17 00:00:00 2001 From: zoudm <908877630@qq.com> Date: Thu, 18 Aug 2022 16:05:28 +0800 Subject: [PATCH 2/5] Create node.js.yml --- .github/workflows/node.js.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..989ad19 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 16.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm install + - run: npm test From ebfd13324caad5cf2bd3d4ff9aa2d7b5ed03c900 Mon Sep 17 00:00:00 2001 From: demin Date: Thu, 18 Aug 2022 16:07:00 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/add.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/add.js b/lib/add.js index c69f4a4..795b752 100644 --- a/lib/add.js +++ b/lib/add.js @@ -15,7 +15,6 @@ function add(num1, num2) { let flag = 0; for (let i = 0; i < minLen; i++) { let sum = +maxANum[i] + +minANum[i] + flag; - maxANum[i] = sum % 10; flag = parseInt(sum / 10); } From ba7b6ad8f6773ca8a15971a506b0c6eae09199c7 Mon Sep 17 00:00:00 2001 From: demin Date: Thu, 18 Aug 2022 16:50:26 +0800 Subject: [PATCH 4/5] workflows --- .github/workflows/node.js.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 989ad19..16493a1 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [16.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: @@ -26,6 +26,5 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - run: npm install - - run: npm test + - run: npm test-one From e924629c7689fcee072e4a2837934ed32c431b41 Mon Sep 17 00:00:00 2001 From: demin Date: Thu, 18 Aug 2022 17:07:07 +0800 Subject: [PATCH 5/5] workflows --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 16493a1..9d0a9ce 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -27,4 +27,4 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm install - - run: npm test-one + - run: npm test