JSFiddle - React, Tailwind, and code Playground
by chriswilsondc
HTML
<div id="test"></div>
JavaScript
function normalize(raw) {
// raw E [1,7]
var fudge = 0.2;
//normalize score to 0
var norm = raw - 1;
// tile E [-3.2, 2.8]
var tilt = norm - (3 + fudge);
if (tilt < 0) {
var score = Math.round(50 * tilt / (3 + fudge));
console.log(tilt);
} else {
var score = Math.round(50 * tilt / (3 - fudge));
}
score += 50;
$("#test").append("<div>" + raw + " -> " + score + "</div>");
}
normalize(1);
normalize(7);
normalize(4);
normalize(4.2);