计算一个圆的完整转弯

时间:2019-05-12 09:49:35

标签: javascript

我对这个作业有疑问

我无法弄清楚如何计数超过360度。我得到4组度数90、368、809和2500作为参数。

function calculateFullTurns(degrees) {
    // return the number of full turns you can make with the provided degrees
    // 1 full turn === 360 degrees

1 个答案:

答案 0 :(得分:2)

您可以使用reduce()得到所有参数的总和,然后除以360。也要对结果使用Math.floor(),因为您想整转

function fullTurns(...args){
  return Math.floor(args.reduce((ac,a) => ac+a,0)/360)
}
console.log(fullTurns(90, 368, 809,2500))