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 diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml new file mode 100644 index 0000000..30ec535 --- /dev/null +++ b/.github/workflows/run-test.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: [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: 'yarn' + - run: yarn + - run: yarn test 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;