Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21461 > unrolled thread
| Started by | "Tony Johansson" <johansson.andersson@telia.com> |
|---|---|
| First post | 2013-09-29 15:11 +0200 |
| Last post | 2013-09-29 16:43 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.javascript
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
| From | "Tony Johansson" <johansson.andersson@telia.com> |
|---|---|
| Date | 2013-09-29 15:11 +0200 |
| Subject | Can I simplify this function UpdateBokningsArray by using some sort of generic formula |
| Message-ID | <l298v8$n5$1@dont-email.me> |
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
function UpdateBokningsArray(seatNr)
{
switch (seatNr)
{
case 1:
case 2:
case 3:
bokningsArray[0][seatNr] = "BOOKED";
break;
case 4:
case 5:
case 6:
bokningsArray[1][seatNr] = "BOOKED";
break;
case 7:
case 8:
case 9:
bokningsArray[2][seatNr] = "BOOKED";
break;
case 10:
case 11:
case 12:
bokningsArray[3][seatNr] = "BOOKED";
break;
case 13:
case 14:
case 15:
bokningsArray[4][seatNr] = "BOOKED";
break;
case 16:
case 17:
case 18:
bokningsArray[5][seatNr] = "BOOKED";
break;
}
}
//Tony
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2013-09-29 15:30 +0100 |
| Message-ID | <0.74438714b5f725435410.20130929153005BST.87had3vgya.fsf@bsb.me.uk> |
| In reply to | #21461 |
"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.
[toc] | [prev] | [next] | [standalone]
| From | "Tony Johansson" <johansson.andersson@telia.com> |
|---|---|
| Date | 2013-09-29 16:43 +0200 |
| Message-ID | <l29ea7$sta$1@dont-email.me> |
| In reply to | #21462 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web