[javascript]代码库
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
var arr = [1,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]
console.log(oddSum);
}else{
evenSum += arr[i]
}
}
return {
"evenSum":evenSum,
"oddSum":oddSum,
}
}
var result = sum(arr)
alert('数组奇数和:'+result.oddSum+' 数组偶数和:'+result.evenSum)
};
</script>
</body>
</html>
by: 发表于:2017-10-17 15:03:18 顶(0) | 踩(0) 回复
??
回复评论