惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - 君临天下之徐少

nvm安装 Homebrew 安装 Less的优点 什么是nrm React函数式组件值之useRef()和useImperativeHandle() 谷歌刷题插件安装 SSL certificate problem: unable to get local issuer certificate 错误解决 常用命令 Mac安装Nvm Node开发环境 解决Mac安装Homebrew失败 Canvas学习:globalCompositeOperation详解 React.CreateContext html让容器居中,css让容器水平垂直居中的7种方式 js下载文件防止白屏 GitHub上README.md编写教程(基本语法) 微信字体大小调整导致的H5页面错乱问题处理 G6-Editor 编辑器入门使用教程 git reset 加不加 --hard的区别 taro, h5拨打电话和发送短信
js 处理大数相减
君临天下之徐少 · 2023-01-13 · via 博客园 - 君临天下之徐少
        function sub(num1, num2) {
            if(num1 === num2) return '0'
            function lt(num1, num2) {
                if (num1.length < num2.length) {
                    return true
                } else if (num1.length === num2.length) {
                    return num1 < num2
                } else {
                    return false
                }
            }
            let isMinus = false
            if (lt(num1, num2)) {
                [num1, num2] = [num2, num1]
                isMinus = true
            }

            let len = Math.max(num1.length, num2.length)
            num1 = num1.padStart(len, 0)
            num2 = num2.padStart(len, 0)

            let flag = 0,
                result = '',
                temp
            for (let i = len - 1; i >= 0; i--) {
                temp = parseInt(num1[i]) - flag - parseInt(num2[i])
                if (temp < 0) {
                    result = (10 + temp) + result
                    flag = 1
                } else {
                    result = temp + result
                    flag = 0
                }
            }
            result = (isMinus ? '-' : '') + result.replace(/^0+/, '')
            return result
        }
        // 传入字符串格式
        console.log(sub('9999999999011112','9999999999011111'
)) // 1
    console.log(sub('9999999999011112','9999999999011113'
)) // -1