<script type="text/javascript"> //求平均数 function Evg() { Array.prototype.sort.call(arguments,function (a,b) { return a-b; }); Array.prototype.pop.call(arguments); Array.prototype.shift.call(arguments); return (eval(Array.prototype.join.call(arguments,"+"))/arguments.length).toFixed(2) } console.log(Evg(10, 90, 10, 10));//10.00 </script> <script type="text/javascript"> //独创继承法/ function myEvg() { arguments.__proto__=Array.prototype; arguments.sort( (a,b)=>(a-b)).pop(); arguments.shift(); return (eval(arguments.join("+"))/arguments.length).toFixed(2) } console.log(myEvg(10, 90, 10, 10)); //10.00 // (存在兼容问题)【移动端可以】 在IE下不允许使用__proto__ </script>
通过继承方式求平均数
最新推荐文章于 2021-05-30 15:28:11 发布