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

31 lines
692 B
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>