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


Groups > comp.lang.javascript > #15990 > unrolled thread

Simplifying a simple line of code

Started byrafaelfaria@gmail.com
First post2012-09-19 02:25 -0700
Last post2012-09-19 03:16 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#15990 — Simplifying a simple line of code

Fromrafaelfaria@gmail.com
Date2012-09-19 02:25 -0700
SubjectSimplifying 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]


#15991

FromShang Wenbin <wbshang@gmail.com>
Date2012-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