From ddc24d3fa1a2af58bb5f63b5296d0e361e052d91 Mon Sep 17 00:00:00 2001 From: hyin08 Date: Sun, 21 Aug 2022 00:39:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?execrise=202=20=E5=A4=A7=E6=95=B0=E7=9B=B8?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/node.js.yml | 30 ++++++++++++++++++++++++++++++ lib/add.js | 12 +++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) 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..655bf28 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,30 @@ +# 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: [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 }} + - run: yarn + # Just run tests once + - run: yarn test-once diff --git a/lib/add.js b/lib/add.js index 1714b95..74f064e 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,5 +1,15 @@ -function add() { +function add(num1, num2) { // 实现该函数 + let len1 = num1.length; + let len2 = num2.length; + let sum = ''; + let carry = 0; + while(len1 || len2 || carry) { + let cur = (len1 ? Number(num1.charAt(--len1)) : 0) + (len2 ? Number(num2.charAt(--len2)) : 0) + carry; + sum = cur % 10 + sum; + carry = Math.floor(cur / 10); + } + return sum; } module.exports = add \ No newline at end of file From 7d550d0f049224ea7f981d6ef2df167f3dc1abfd Mon Sep 17 00:00:00 2001 From: hyin08 Date: Sun, 21 Aug 2022 10:08:42 +0800 Subject: [PATCH 2/2] update node.js.yml --- .github/workflows/node.js.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 655bf28..a327bf2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -26,5 +26,4 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: yarn - # Just run tests once - - run: yarn test-once + - run: yarn test