31 lines
692 B
HTML
31 lines
692 B
HTML
<!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> |