From fb5e1f05fc2042ca6c898ae11a5cfb0c4365de4a Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:02:29 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=A4=A7=E6=95=B4?= =?UTF-8?q?=E6=95=B0=E7=9B=B8=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/add.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/add.js b/lib/add.js index 1714b95..3b9c2b7 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,5 +1,20 @@ -function add() { +function add(a, b) { // 实现该函数 + const maxLength = Math.max(a.length, b.length); + const aPad = a.padStart(maxLength, "0"); + const bPad = b.padStart(maxLength, "0"); + + let sum = ""; + let f = 0; + for (let i = maxLength - 1; i >= 0; i--) { + const digit = parseInt(aPad[i]) + parseInt(bPad[i]) + f; + f = Math.floor(digit / 10); + sum = (digit % 10) + sum; + } + if (f === 1) { + sum = "1" + sum; + } + return sum; } -module.exports = add \ No newline at end of file +module.exports = add; From 323105896c6a853edf86c69b650775a775d413c4 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:19:58 +0800 Subject: [PATCH 2/8] add github actions --- .github/workflows/learn-github-actions.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/learn-github-actions.yml diff --git a/.github/workflows/learn-github-actions.yml b/.github/workflows/learn-github-actions.yml new file mode 100644 index 0000000..017593f --- /dev/null +++ b/.github/workflows/learn-github-actions.yml @@ -0,0 +1,12 @@ +name: learn-github-actions +on: [push] +jobs: + check-bats-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '14' + - run: npm install -g bats + - run: bats -v \ No newline at end of file From 4a05620a6be58ec29e8d03aaff12055d21271ecf Mon Sep 17 00:00:00 2001 From: TomatoDroid <770226915@qq.com> Date: Sat, 20 Aug 2022 21:34:07 +0800 Subject: [PATCH 3/8] Create node.js.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit push代码后运行单元测试 --- .github/workflows/node.js.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 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..083d3a3 --- /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: Run test + +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 test From 0552260a9df7fc63fff304493a26b5203f9b22a3 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:44:41 +0800 Subject: [PATCH 4/8] =?UTF-8?q?actions-push=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BF=90=E8=A1=8Ctest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/run-test.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/run-test.yml diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml new file mode 100644 index 0000000..1508136 --- /dev/null +++ b/.github/workflows/run-test.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: run-test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [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 install yarn + - run: yarn + - run: yarn test From bc635f44414edb11388037a8bf67084432d3cfe5 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:48:39 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=9C=E7=AB=AF?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=9A=84github=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/node.js.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 083d3a3..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,30 +0,0 @@ -# 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: Run test - -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 test From 08a5e42f9d21075097c08e91b04de514e54124f7 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:50:42 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=B0=86=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=94=B9=E9=94=99=EF=BC=8C=E6=B5=8B=E8=AF=95githubAct?= =?UTF-8?q?ions=E8=BF=90=E8=A1=8C=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.spec.js b/test/test.spec.js index 935b70e..771f4df 100644 --- a/test/test.spec.js +++ b/test/test.spec.js @@ -2,7 +2,7 @@ var add = require('../lib/add') describe('大数相加add方法', function () { test('字符串"42329"加上字符串"21532"等于"63861"', function () { - expect(add('42329', '21532')).toBe('63861') + expect(add('42329', '21532')).toBe('6386') }) test('"843529812342341234"加上"236124361425345435"等于"1079654173767686669"', function () { From 5131448160454324ae97f665be7c9475ed9b60c9 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sat, 20 Aug 2022 21:51:44 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.spec.js b/test/test.spec.js index 771f4df..935b70e 100644 --- a/test/test.spec.js +++ b/test/test.spec.js @@ -2,7 +2,7 @@ var add = require('../lib/add') describe('大数相加add方法', function () { test('字符串"42329"加上字符串"21532"等于"63861"', function () { - expect(add('42329', '21532')).toBe('6386') + expect(add('42329', '21532')).toBe('63861') }) test('"843529812342341234"加上"236124361425345435"等于"1079654173767686669"', function () { From 8ad4fa7c6324bc84416a2fb9b89f61dcd63f4fd4 Mon Sep 17 00:00:00 2001 From: zhen <770226915@qq.com> Date: Sun, 21 Aug 2022 09:57:10 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0github=20action=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/run-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 1508136..30ec535 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -25,7 +25,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm install yarn + cache: 'yarn' - run: yarn - run: yarn test