[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

indexed array

Josselin

2/2/2007 7:37:00 AM

presently I am using : zl = 13-[2,5,10,15,25].index(last_city_km)
when last_city_km is one of these fixed values to get a zoom level,

now, there is a change in customer requirement, last_city_km is calculated, so
last_city_km can be an integer value between 0 and 25,
and I would like to calculate (DRY) the zoom level such as :

last_city_km can be 0

if last_city_km <= 2 then zl = 13
if 2 < last_city_km <= 5 then zl = 12
if 5 < last_city_km <= 10 then zl = 12
if 10 < last_city_km <= 15 then zl = 12
if 15 < last_city_km <= 25 then zl = 12

if 25 < last_city_km.... cannot !

thanks for

2 Answers

Jano Svitok

2/2/2007 8:48:00 AM

0

On 2/2/07, Josselin <josselin@wanadoo.fr> wrote:
> presently I am using : zl = 13-[2,5,10,15,25].index(last_city_km)
> when last_city_km is one of these fixed values to get a zoom level,
>
> now, there is a change in customer requirement, last_city_km is calculated, so
> last_city_km can be an integer value between 0 and 25,
> and I would like to calculate (DRY) the zoom level such as :
>
> last_city_km can be 0
>
> if last_city_km <= 2 then zl = 13
> if 2 < last_city_km <= 5 then zl = 12
> if 5 < last_city_km <= 10 then zl = 11
> if 10 < last_city_km <= 15 then zl = 10
> if 15 < last_city_km <= 25 then zl = 9
>
> if 25 < last_city_km.... cannot !
>
> thanks for

13 - [2,5,10,15,25].select{|i| last_city_km <= i}.size - 1
==
14 - [2,5,10,15,25].select{|i| last_city_km <= i}.size

Ara.T.Howard

2/2/2007 1:31:00 PM

0