Given two ranges:

   



[

a

1


,

a

2


]


{\displaystyle [a_{1},a_{2}]}

   and 
   



[

b

1


,

b

2


]


{\displaystyle [b_{1},b_{2}]}

; 
   then a value   



s


{\displaystyle s}

   in range   



[

a

1


,

a

2


]


{\displaystyle [a_{1},a_{2}]}


   is linearly mapped to a value   



t


{\displaystyle t}

   in range   



[

b

1


,

b

2


]


{\displaystyle [b_{1},b_{2}]}


   where:



   



t
=

b

1


+



(
s
−

a

1


)
(

b

2


−

b

1


)


(

a

2


−

a

1


)





{\displaystyle t=b_{1}+{(s-a_{1})(b_{2}-b_{1}) \over (a_{2}-a_{1})}}




Task

Write a function/subroutine/... that takes two ranges and a real number, and returns the mapping of the real number from the first to the second range.

Use this function to map values from the range    [0, 10]    to the range    [-1, 0]. 



Extra credit

Show additional idiomatic ways of performing the mapping, using tools available to the language.




 
{def maprange
 {lambda {:a0 :a1 :b0 :b1 :s}
  {+ :b0 {/ {* {- :s :a0} {- :b1 :b0}} {- :a1 :a0}}}}}
-> maprange
 
{maprange 0 10 -1 0 5}
-> -0.5
 
{S.map {maprange 0 10 -1 0} {S.serie 0 10}}
-> 
0 maps to -1 
1 maps to -0.9 
2 maps to -0.8 
3 maps to -0.7 
4 maps to -0.6 
5 maps to -0.5 
6 maps to -0.4 
7 maps to -0.30000000000000004 
8 maps to -0.19999999999999996 
9 maps to -0.09999999999999998 
10 maps to 0
 