【Edabit 算法 ★☆☆☆☆☆】【求三角形面积】Area of a Triangle

编程入门 行业动态 更新时间:2024-10-24 20:22:23

【Edabit 算法 ★☆☆☆☆☆】【求三<a href=https://www.elefans.com/category/jswz/34/1769024.html style=角形面积】Area of a Triangle"/>

【Edabit 算法 ★☆☆☆☆☆】【求三角形面积】Area of a Triangle

【Edabit 算法 ★☆☆☆☆☆】【求三角形面积】Area of a Triangle

math numbers geometry

Instructions

Write a function that takes the base and height of a triangle and return its area.

Examples
triArea(3, 2) // 3
triArea(7, 4) // 14
triArea(10, 10) // 50
Notes
  • The area of a triangle is: (base * height) / 2
  • Don’t forget to return the result.
Solutions
function triArea(base, height) {return base*height/2;	
}
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(triArea(3, 2), 3)
Test.assertEquals(triArea(5, 4), 10)
Test.assertEquals(triArea(10, 10), 50)
Test.assertEquals(triArea(0, 60), 0)
Test.assertEquals(triArea(12, 11), 66)

更多推荐

【Edabit 算法 ★☆☆☆☆☆】【求三角形面积】Area of a Triangle

本文发布于:2023-12-06 03:39:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1666331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角形   算法   面积   Edabit   Area

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!