Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Auto Test CI

on:
push:
branches: ['master']

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

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 i
- run: npm run test
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Readme
# Readme [![Node.js CI](https://github.com/chris-wang/exercise2/actions/workflows/node.js.yml/badge.svg)](https://github.com/chris-wang/exercise2/actions/workflows/node.js.yml)

### 步骤

Expand All @@ -20,4 +20,4 @@ npm run test
### 参考

* [Jest](https://jestjs.io/zh-Hans/)
* [Github Actions](https://docs.github.com/cn/actions)
* [Github Actions](https://docs.github.com/cn/actions)
21 changes: 19 additions & 2 deletions lib/add.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
function add() {
function add(num1, num2) {
// 实现该函数
let maxLength = Math.max(num1.length, num2.length);
num1 = num1.padStart(maxLength, '0');
num2 = num2.padStart(maxLength, '0');

let temp = 0;
let flag = 0;
let result = '';
for (let i = maxLength - 1; i >= 0; i--) {
temp = parseInt(num1[i]) + parseInt(num2[i]) + flag;
flag = Math.floor(temp / 10);
result = (temp % 10) + result;
}

if (flag === 1) {
result = '1' + result;
}
return result;
}

module.exports = add
module.exports = add;
Loading