Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21463
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| 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 | Sun, 29 Sep 2013 16:43:06 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 44 |
| Message-ID | <l29ea7$sta$1@dont-email.me> (permalink) |
| References | <l298v8$n5$1@dont-email.me> <0.74438714b5f725435410.20130929153005BST.87had3vgya.fsf@bsb.me.uk> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="iso-8859-1"; reply-type=original |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sun, 29 Sep 2013 14:43:19 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="8fdc2b5af81c338deb7045fc6c39b0e2"; logging-data="29610"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19f7hdzt49o/k6Q8QkLaUWF" |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.0.6002.18463 |
| In-Reply-To | <0.74438714b5f725435410.20130929153005BST.87had3vgya.fsf@bsb.me.uk> |
| X-Newsreader | Microsoft Windows Mail 6.0.6002.18197 |
| Cancel-Lock | sha1:UxBeQfvlsq/hJE0HgiGk79iYtyA= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| Xref | csiph.com comp.lang.javascript:21463 |
Show key headers only | 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
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