JavaScript
const avg = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length
Examples
avg(...[1, 2, 3]) // 2
avg(1, 2, 3) // 2
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288105.html
const avg = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length
avg(...[1, 2, 3]) // 2
avg(1, 2, 3) // 2
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288105.html