0010【Edabit ★☆☆☆☆☆】Maximum Edge of a Triangle

【Edabit 算法 ★☆☆☆☆☆】Maximum Edge of a Triangle

algorithms math numbers

Instructions

Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers.

Examples
javascript 复制代码
nextEdge(8, 10) // 17
nextEdge(5, 7) // 11
nextEdge(9, 2) // 10
Notes
  • (side1 + side2) - 1 = maximum range of third edge.
  • The side lengths of the triangle are positive integers.
  • Don't forget to return the result.
Solutions
javascript 复制代码
function nextEdge(side1, side2) {
    return side1 + side2 - 1;
}
TestCases
javascript 复制代码
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        }
    }
})();

Test.assertEquals(nextEdge(5, 4), 8)
Test.assertEquals(nextEdge(8, 3), 10)
Test.assertEquals(nextEdge(7, 9), 15)
Test.assertEquals(nextEdge(10, 4), 13)
Test.assertEquals(nextEdge(7, 2), 8)
相关推荐
小侯不躺平.3 分钟前
C++ Boost库【2】 --stringalgo字符串算法
linux·c++·算法
流年如夢16 分钟前
二叉树详解
c语言·数据结构·算法
xiaoxiaoxiaolll24 分钟前
Nature Communications:三维超原子库+原子层保护,突破全彩VR超透镜量产瓶颈
人工智能·算法
仍然.25 分钟前
算法题目---栈
算法
feifeigo12328 分钟前
基于布谷鸟算法的配电网分布式电源选址定容 MATLAB 实现
开发语言·算法·matlab
scan72437 分钟前
pydantic格式输出
服务器·前端·javascript
ZC跨境爬虫43 分钟前
跟着MDN学HTML_day44:(ProcessingInstruction接口)
前端·javascript·ui·html·媒体
MicroTech20251 小时前
微算法科技(NASDAQ: MLGO)噪声图像的量子图像边缘提取算法:技术革新与产业赋能
科技·算法·量子计算
大模型最新论文速读1 小时前
EvoLM:8B 模型自写评分标准,RL 后超越 GPT-4
人工智能·深度学习·算法·机器学习·自然语言处理
木子墨5161 小时前
工程算法实战 | 从LRU到手写本地缓存:LinkedHashMap → 双向链表+哈希表 → Caffeine 原理
java·数据结构·算法·链表·缓存