/** * */ const multiplier_temperature = 5; /** * * @param {...any} scores expects objects which contains score and their weight */ function calculateAvgScore(...scores) { return avgScore = scores.reduce((total, score) => total += score) / scores.length; } function calculateScoreRange(min, max, multiplier, targetVal, sLowVal, sHighVal) { // return full score when in range if (targetVal >= sLowVal && targetVal <= sHighVal) return 10; // choose value with smallest distance let sVal = Math.abs(targetVal - sLowVal) < Math.abs(targetVal - sHighVal) ? sLowVal : sHighVal; return calculateScore(min, max, multiplier, targetVal, sVal); } function calculateScore(min, max, multiplier, targetVal, searchVal) { let score = 1 - (Math.abs(searchVal - targetVal) / (max - min) * multiplier); return score <= 0 ? 0 : score * 10; } console.log('Calc') console.log(calculateScoreRange(-15, 45, 5, 24, 15, 22))