From e1912314e564c0fa5b2e8f9e1e262ed80df96ba9 Mon Sep 17 00:00:00 2001 From: luohuidong Date: Sun, 21 Aug 2022 20:12:33 +0800 Subject: [PATCH 1/2] complete exercise2 --- lib/add.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/add.js b/lib/add.js index 1714b95..1b97713 100644 --- a/lib/add.js +++ b/lib/add.js @@ -1,5 +1,11 @@ -function add() { - // 实现该函数 +function add(num1, num2) { + const tmp1 = Number(num1); + const tmp2 = Number(num2); + if (Number.isSafeInteger(tmp1) && Number.isSafeInteger(tmp2)) { + return (tmp1 + tmp2).toString(); + } else { + return (BigInt(num1) + BigInt(num2)).toString(); + } } -module.exports = add \ No newline at end of file +module.exports = add; From 2c21d105dd239b1a40fdf35fa8cefbb52f5b8c7d Mon Sep 17 00:00:00 2001 From: luohuidong Date: Sun, 21 Aug 2022 21:05:02 +0800 Subject: [PATCH 2/2] add github actions file --- .github/workflows/node.js.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 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..3a2d08b --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,29 @@ +# 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 }} + cache: "npm" + - run: npm install + - run: npm run test