Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大数相加函数 #267

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: GitHub Actions Demo
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
16 changes: 15 additions & 1 deletion lib/add.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function add() {
function add(n1,n2) {
// 实现该函数
const n1Arr = n1.split('')
const n2Arr = n2.split('')
const resultArr = [];
let count = 0;
const maxLength = n1Arr.length>n2Arr.length?n1Arr.length:n2Arr.length
for(let i=maxLength-1;i>=0;i--){
const sum = Number(n1Arr[i])+Number(n2Arr[i])+count;
resultArr.unshift(sum%10)
count = sum>9?1:0
}
if(count>0){
resultArr.unshift(count)
}
return resultArr.join('')
}

module.exports = add