<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var arr = [2,3,4,5,6,7]
function sum(arr){
var evenSum = 0,oddSum = 0
for(var i=0; i<arr.length;i++){
if(arr[i] % 2){
oddSum += arr[i]
}else{
evenSum += arr[i]
}
}
return {
"evenSum":evenSum,
"oddSum":oddSum,
}
}
var result = sum(arr)
alert('数组奇数和:'+result.oddSum+' 数组偶数和:'+result.evenSum)
</script>
</head>
<body>
</body>
</html>
数组奇数和
最新推荐文章于 2022-07-19 21:56:26 发布