In other programming languages such as processing, there is a function which allows you to convert a number that falls within a range of numbers into a number within a diffe
For a general purpose mapping function, which is what the OP asked for, go here:
http://rosettacode.org/wiki/Map_range#JavaScript