From 363474403ae0f5365e076f1d941db28c7fd9be9d Mon Sep 17 00:00:00 2001 From: suven Date: Sun, 21 Aug 2022 13:39:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E4=BA=8C=EF=BC=8C=E8=AE=A1=E7=AE=97=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 --- lib/add.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/add.js b/lib/add.js index 1714b95..83eff59 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,5 +1,41 @@ -function add() { +function add(a, b) { // 实现该函数 + // 非数字报错 + if(isNaN(a) || isNaN(b)) throw Error('需要传入数字或字符串型数字') + const maxLength = 16 + // 边界:16位以内可以正常相加 + if(String(a).length=0 || bLength>=0) { + const resultTemp = Number(aList[aLength] || 0) + Number(bList[bLength] || 0) + // 判断长度是否溢出 + if(resultTemp.length > Math.max(aList[aLength].length, bList[bLength].length)) { + addResultList[resultLength - 1] = 1 + resultTemp = resultTemp.slice(1) + } + addResultList[resultLength] = addResultList[resultLength] + resultTemp + + aLength-- + bLength-- + resultLength-- + } + + const result = addResultList.join('') + + return result } module.exports = add \ No newline at end of file From f951436847764c4be0c1fcfbd598670ae6261ad3 Mon Sep 17 00:00:00 2001 From: suven Date: Tue, 23 Aug 2022 20:11:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ACTIONS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test.spec.js b/test/test.spec.js index 935b70e..6ec6493 100644 --- a/test/test.spec.js +++ b/test/test.spec.js @@ -8,4 +8,6 @@ describe('大数相加add方法', function () { test('"843529812342341234"加上"236124361425345435"等于"1079654173767686669"', function () { expect(add('843529812342341234', '236124361425345435')).toBe('1079654173767686669') }) -}) \ No newline at end of file +}) + +// test: add git actions \ No newline at end of file From 184bc96761d8d22f33b45e5ab6038d2a6337b98a Mon Sep 17 00:00:00 2001 From: Su-ven Date: Tue, 23 Aug 2022 20:16:03 +0800 Subject: [PATCH 3/3] Create main.yml --- .github/workflows/main.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0063a3d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,12 @@ +name: 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