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)
相关推荐
Crystal3289 分钟前
冒泡排序 bubble sort
前端·javascript·面试
Learner__Q16 分钟前
每天五分钟:动态规划-LeetCode高频题_day2
算法·leetcode·动态规划
一韦以航.22 分钟前
C【指针】详解(上)
c语言·数据结构·c++·算法
阿蓝灬24 分钟前
clientWidth vs offsetWidth
前端·javascript
用户90443816324601 小时前
从40亿设备漏洞到AI浏览器:藏在浏览器底层的3个“隐形”原理
前端·javascript·浏览器
鸡吃丸子1 小时前
React Native入门详解
开发语言·前端·javascript·react native·react.js
mit6.8241 小时前
固定中间
算法
阿蒙Amon1 小时前
JavaScript学习笔记:12.类
javascript·笔记·学习
老马啸西风1 小时前
成熟企业级技术平台 MVE-010-跳板机 / 堡垒机(Jump Server / Bastion Host)
人工智能·深度学习·算法·职场和发展
阿蒙Amon1 小时前
JavaScript学习笔记:10.集合
javascript·笔记·学习