본문 바로가기
개발/html,Thymeleaf

javascript 함수-1

by 카앙구운 2016. 1. 14.
728x90
반응형

javascript 함수-1

<html>
<head>
<meta charset="utf-8">
<script src="bubble.js"></script>
<script>
var scores=[60,60,40,30,20,10,
61,51,41,31,21,11,
62,52,42,32,22,12,
63,53,43,33,23,13,
64,54,44,34,24,14,
65,55,45,35,65,15];
var costs=[.60,.60,.40,.30,.20,.10,
.61,.51,.41,.31,.21,.11,
.62,.52,.42,.32,.22,.12,
.63,.53,.43,.33,.23,.13,
.64,.54,.44,.34,.24,.14,
.65,.55,.45,.35,.65,.15];
var highScore = printAndget(scores);
var bestSolution=best(scores,highScore);
var extt=minCost(scores,costs);
var exttHighScore = printAndget(extt);
console.log(bestSolution);
console.log("실험횟수:"+scores.length);
console.log("최고점수:"+highScore);
console.log("최대 효율성:"+exttHighScore);
</script>
</head>
<body>
</body>
</html>




bubble.js






function printAndget(scores){
for(var i = 0; i< scores.length; i++){
var highScore = 0;
if(highScore < scores[i]){
highScore = scores[i];
}
}
return highScore;
}
function best(scores, highScore){
var bestSolution=[];
for(var j = 0; j<scores.length; j++){
if(highScore == scores[j]){
bestSolution.push(j);
}
}
return bestSolution;
}
function minCost(scores,costs){
var extt=[];
var exttNumber;
for(var i=0;i<scores.length;i++){
extt.push(scores[i]*costs[i]);
}
console.log(extt);
return extt;
}


728x90
반응형

댓글