Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21463

Re: Can I simplify this function UpdateBokningsArray by using some sort of generic formula

From "Tony Johansson" <johansson.andersson@telia.com>
Newsgroups comp.lang.javascript
Subject Re: Can I simplify this function UpdateBokningsArray by using some sort of generic formula
Date 2013-09-29 16:43 +0200
Organization A noiseless patient Spider
Message-ID <l29ea7$sta$1@dont-email.me> (permalink)
References <l298v8$n5$1@dont-email.me> <0.74438714b5f725435410.20130929153005BST.87had3vgya.fsf@bsb.me.uk>

Show all headers | View raw


Many thanks Ben just what I looked for.

//Tony
"Ben Bacarisse" <ben.usenet@bsb.me.uk> skrev i meddelandet 
news:0.74438714b5f725435410.20130929153005BST.87had3vgya.fsf@bsb.me.uk...
> "Tony Johansson" <johansson.andersson@telia.com> writes:
>
>> I have this matris that is 6 X 4 which is 6 rows and 4 columns
>> var bokningsArray = [["dummy", "", "", ""],
>>                             ["dummy", "", "", ""],
>>                             ["dummy", "", "", ""],
>>                             ["dummy", "", "", ""],
>>                             ["dummy", "", "", ""],
>>                             ["dummy", "", "", ""]];
>>
>> I want to find some sort of  generic formula that I can use instead of
>> doing in the way I have done in the  function UpdateBokningsArray.
>> Now I check if I have seatNr 1,2 or 3 I use row 0
>> If I have seatNr 4,5 or 6 I use row 1
>> If I have seatNr 7,8 or 9 I use row 2 and so on as you can see
>
> You probably want Math.floor((seatNr - 1) / 3).  However...
>
>> function UpdateBokningsArray(seatNr)
>>        {
>>            switch (seatNr)
>>            {
> <snip>
>>                case 10:
>>                case 11:
>>                case 12:
>>                   bokningsArray[3][seatNr] = "BOOKED";
>
> Do you really want to set bokningsArray[3][12]?  I'd expect you want to
> use something like (seatNr - 1) % 3 + 1 (since the zero element seems to
> be unused and seats are numbered from 1.
>
>>                   break;
> <snip>
>>        }
>
> -- 
> Ben. 

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Can I simplify this function UpdateBokningsArray by using some sort of generic formula "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-29 15:11 +0200
  Re: Can I simplify this function UpdateBokningsArray by using some sort of generic formula Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-29 15:30 +0100
    Re: Can I simplify this function UpdateBokningsArray by using some sort of generic formula "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-29 16:43 +0200

csiph-web