Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27147
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: help with script |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <551958fb$0$46998$b1db1813$1367588f@news.astraweb.com> <7e5666d0-f59e-4fc1-87ca-d36ea451a936@googlegroups.com> |
| Date | 2015-03-31 11:16 +0200 |
| Message-ID | <XnsA46E72BB7CCA3eejj99@194.109.6.166> (permalink) |
Scott Sauyet <scott.sauyet@gmail.com> wrote on 31 mrt 2015 in
comp.lang.javascript:
> PeCoNe wrote:
>> [ ... ]
>> if (Ticker != "OIL") {
>> if (Ticker != "EURCHF") {
>> if (Ticker != "EURUSD") {
>> if (Ticker != 'SPG') {
>> [ ... ]
>>
>> Now i must add a few more symbols and i think there is better way then
>> all that nested if's.
>
> There certainly are, many ways. JJ's suggestion is probably a better
> long-term suggestion, as it's easier to extend, but the first thing that
> should probably come to mind is to combine your conditions with and, like
> this:
>
>> if (Ticker != "OIL" && Ticker != "EURCHF" &&
>> Ticker != "EURUSD" && Ticker != 'SPG') {
** or use string indexOf():
if (',OIL,EURCHF,EURUSD,SPG,'.indexOf(','+Ticker+',')=-1) {
** or use Regex:
if
(!',OIL,EURCHF,EURUSD,SPG,'.test(new RegExp(','+Ticker+','))){
** or an easily explandable switch:
switch(Ticker) {
case 'OIL': break;
case 'EURCHF': break;
....
default:
{do what you wat to do};
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
help with script PeCoNe <maljers@telfort.nl> - 2015-03-30 16:08 +0200
Re: help with script JJ <jj4public@vfemail.net> - 2015-03-30 21:44 +0700
Re: help with script Scott Sauyet <scott.sauyet@gmail.com> - 2015-03-30 19:09 -0700
Re: help with script "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-03-31 11:16 +0200
csiph-web