Evertjan.
3/31/2015 9:17:00 AM
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)