Tested in VS Codium and at https://regex101.com
\/\*[\s\S\n]*?\*\/|\/\/.*$
// single line comments
\/\*[\s\S\n]*?\*\/|\/\/.*$
// single line comments
function convertRange( value, r1, r2 ) { | |
return ( value - r1[ 0 ] ) * ( r2[ 1 ] - r2[ 0 ] ) / ( r1[ 1 ] - r1[ 0 ] ) + r2[ 0 ]; | |
} | |
// example | |
convertRange(26, [0, 100], [-2, 2]); | |
// = -0.96 | |
// another example | |
convertRange(26, [0, 100.1], [-2, 2]); |