Skip to content

Commit

Permalink
Conditionals only using logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Bin committed Feb 2, 2012
1 parent c7c7f0c commit aa70e73
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions general-patterns/conditionals.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@
} else if (value == 2) {
return result2;
}


// define the array of results
var results = [result0, result1, result2];
// return the correct result
return results[value];


/* alternative method 5 - only using logical operators
* Shorter way to use simple statements
Expand All @@ -126,12 +131,7 @@
type == 'foo' && type2 == 'bar' && result == 3 && (result=0); //parentheses avoid "invalid assignment left-hand side" error
console.log(result); //0
type == 'OOF' || result++; //equivalent: type != 'OFF' && result++;
console.log(result); //1

// define the array of results
var results = [result0, result1, result2];
// return the correct result
return results[value];
console.log(result); //1


// References
Expand Down

0 comments on commit aa70e73

Please sign in to comment.