vue222/07-v-for属性的使用/练习Js高阶函数.html

31 lines
692 B
HTML
Raw Normal View History

2022-10-15 10:05:34 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script>
// 案例取出小于50的数每个数乘以平方进行求平均值
list=[]
let count=0
for(let i=0;i<100;i++){
let maths=Math.ceil(Math.random()*10+1)
list.push(maths)
}
let result=list.filter(function(n){
return n<100//条件
}).map(function(n){
count=count+1
return n/2 ;;//运算
}).reduce(function(pre,n){
return pre+n//汇总
},0)
console.log(result);
</script>
</html>