Skip to content

Commit

Permalink
Make the boolean conditionals examples equivalent
Browse files Browse the repository at this point in the history
`array.indexOf(i) >= -1` will return `true` when `array.indexOf(i)` is -1 or greater. `array.indexOf(i) !== -1` will return `true` when `array.indexOf(i)` is not -1. Since `Array.prototype.indexOf` returns values starting from -1, that is equivalent to `array.indexOf(i) >= 0`. This pull request makes both expressions equivalent.
  • Loading branch information
davissorenson committed Aug 30, 2016
1 parent 1f3538f commit 6681495
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions workflow/boolean-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Avoid using `>=` and `<=` unless necessary. It's faster to use a simpler compari

```js
// slow
// two boolean conditions: `=== -1` and `> -1`
array.indexOf(i) >= -1
// two boolean conditions: `=== 0` and `> 0`
array.indexOf(i) >= 0

// fast
// just one boolean condition: `!== -1`
Expand Down

0 comments on commit 6681495

Please sign in to comment.