/**
* @file
* Global vanilla JavaScript maths functions.
*/
/* global UCASUtilities */
'use strict';
/**
* @param {object} _u - UCASUtilities object.
*/
(function (_u) {
/**
* Map a value to a specific range.
* @function mapRange
* @param {number} number - The number being mapped
* @param {array} from - The range being mapped from
* @param {array} to - The range being mapped to
* @param {boolean} round - Whether to round to the nearest whole number
* @return {number} - The mapped number
*/
function mapRange (number, from, to, round) {
round = (round === undefined) ? true : round
var result = to[0] + (number - from[0]) * (to[1] - to[0]) / (from[1] - from[0])
return round ? Math.round(result) : result
}
_u.maths = {
mapRange: mapRange
}
})(UCASUtilities)