Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15990 > unrolled thread
| Started by | rafaelfaria@gmail.com |
|---|---|
| First post | 2012-09-19 02:25 -0700 |
| Last post | 2012-09-19 03:16 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
Simplifying a simple line of code rafaelfaria@gmail.com - 2012-09-19 02:25 -0700
Re: Simplifying a simple line of code Shang Wenbin <wbshang@gmail.com> - 2012-09-19 03:16 -0700
| From | rafaelfaria@gmail.com |
|---|---|
| Date | 2012-09-19 02:25 -0700 |
| Subject | Simplifying a simple line of code |
| Message-ID | <9abadd3e-4b0f-4e37-8d2d-6739dbd97cc3@googlegroups.com> |
Hey Guys, I was hoping you guys could help me out to simplify the below line of code last_direction = "up"; // it will be dynamically var opposite = (last_direction == "up" ? "down" : ((last_direction == "down") ? "up" : ((last_direction == "left") ? "right" : ((last_direction == "right") ? "left": "")))) How can I write the "opposite" in a better sintaxe?! Anyone? Thanks
[toc] | [next] | [standalone]
| From | Shang Wenbin <wbshang@gmail.com> |
|---|---|
| Date | 2012-09-19 03:16 -0700 |
| Message-ID | <b4bf700d-a90b-40f2-a4b4-59f6fda91988@googlegroups.com> |
| In reply to | #15990 |
var opposite = { up: "down", down: "up", left: "right", right: "left" }[last_direction];
On Wednesday, September 19, 2012 5:25:21 PM UTC+8, rafae...@gmail.com wrote:
> Hey Guys,
>
>
>
> I was hoping you guys could help me out to simplify the below line of code
>
>
>
> last_direction = "up"; // it will be dynamically
>
>
>
> var opposite = (last_direction == "up" ? "down" : ((last_direction == "down") ? "up" : ((last_direction == "left") ? "right" : ((last_direction == "right") ? "left": ""))))
>
>
>
> How can I write the "opposite" in a better sintaxe?!
>
>
>
> Anyone?
>
> Thanks
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web