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


Groups > comp.lang.javascript > #15990

Simplifying a simple line of code

Newsgroups comp.lang.javascript
Date 2012-09-19 02:25 -0700
Message-ID <9abadd3e-4b0f-4e37-8d2d-6739dbd97cc3@googlegroups.com> (permalink)
Subject Simplifying a simple line of code
From rafaelfaria@gmail.com

Show all headers | View raw


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

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


Thread

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

csiph-web