From: Josselin Date: 2006-10-20T19:45:07+09:00 Subject: Re: filling an array excepted first and last position... On 2006-10-20 10:26:50 +0200, "Rimantas Liubertas" said: >> ldom = 30 # variable (last day of a month...) >> >> # array init to 0 >> @obk = [] >> 1.step(ldom, 1) do |i| >> @obk[i] = 0 >> end > > Why not: > > @obk = Array.new(ldom,0) yes , it's better .... avoiding @obk[0] = nil in my writing... > > >> I am filling an array as follows (part of a larger filling scheme) : >> ---- >> #fiiling the array upon another array content >> # but I'd like to AVOID filling the first and last position in this loop.... >> obdays.each do |bd| >> @obk[bd] = 1 >> end > <...> > > Not sure what are you trying to do here, but maybe something like this > may suit you? > > @obk.fill(1,ldom-1){|i| obdays[i]} obdays are all days in a given period in a month (ex : 2 to 6 november) I need to fill @obk[3] = 1 ...... @obk[5] = 1 # booked but @obk[2] += -1 (in value) @obk[6] += -2 (out value) why adding these values ? because on november 6, I can also have late another booking period starting so I will get @obk[6] += 1 (in value)... in which case @obk[6] will be -3 finally I got my array for november from 1 to 30 Day 1 2 3 4 5 6 7 8 9 ...... value 0 -1 1 1 1 -3 1 1 1 ..... these values are used in a javascript calendar to fix the CSS class for display 0 no booking color -1 half day starting 1 booked day -3 half day ending / half day starting .. -2 half day ending that's it.... > > > Regards, > Rimantas