100) { user.score = 100; } else if(user.score < 0) { user.score = 0; } // 평가를 유저의 평가 목록에 추가합니다. user.evaluations.push(`스터디${user.evaluations.length + 1}`); } for(let i=0; i<20; i++){ updateScore(user, newEvaluation) console.log(`스터디 ${i+1} 후의 점수: ${user.score.toFixed(1)}`); } "> 100) { user.score = 100; } else if(user.score < 0) { user.score = 0; } // 평가를 유저의 평가 목록에 추가합니다. user.evaluations.push(`스터디${user.evaluations.length + 1}`); } for(let i=0; i<20; i++){ updateScore(user, newEvaluation) console.log(`스터디 ${i+1} 후의 점수: ${user.score.toFixed(1)}`); } "> 100) { user.score = 100; } else if(user.score < 0) { user.score = 0; } // 평가를 유저의 평가 목록에 추가합니다. user.evaluations.push(`스터디${user.evaluations.length + 1}`); } for(let i=0; i<20; i++){ updateScore(user, newEvaluation) console.log(`스터디 ${i+1} 후의 점수: ${user.score.toFixed(1)}`); } ">
const user = {evaluations: ["스터디1"], score: 0}
const newEvaluation = 8
function updateScore(user, newEvaluation) {
// 가중치는 유저가 받은 평가의 수의 제곱근입니다.
let weight = 10 / user.evaluations.length
// 새로운 점수는 가중치와 새로운 평가를 곱한 값입니다.
let newScore = Math.sqrt(weight * newEvaluation) * 3;
// 유저의 점수를 업데이트합니다.
user.score += newScore;
// 점수가 100을 초과하면 100으로, 0 미만이면 0으로 맞춥니다.
if(user.score > 100) {
user.score = 100;
} else if(user.score < 0) {
user.score = 0;
}
// 평가를 유저의 평가 목록에 추가합니다.
user.evaluations.push(`스터디${user.evaluations.length + 1}`);
}
for(let i=0; i<20; i++){
updateScore(user, newEvaluation)
console.log(`스터디 ${i+1} 후의 점수: ${user.score.toFixed(1)}`);
}
