本文主要是介绍【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
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
function nextEdge(side1, side2) {return side1 + side2 - 1;
}
TestCases
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)
这篇关于【Edabit 算法 ★☆☆☆☆☆】Maximum Edge of a Triangle的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!