197
reputation
1
3
16

VLAZ

To be, or not to be, that is the question

Translating it into code, we get

theQuestion = 2b || !2b

This returns true for any value of 2b, making the evaluation redundant. We can optimise it by removing the expression and substituting with the result.

theQuestion = true

Pet peeves:

  • Using .map() (or any other array method like .filter, etc), in JavaScript for simple iteration instead of .forEach(). In general, use the array methods for their purpose:
    • .map - I have an array, I another array where each item is based on the first one
    • .flatMap - like .map but I use it when each new item also an array
    • .filter - I have an array, I need less of it
    • .find - I have an array, I need one item from it
    • .findIndex - I have an array, I need the index of an item
    • .some - I have an array, I need to check if at least one item passes a check
    • .every - I have an array, I need to see if all items pass a check
    • .forEach - I have an array, I need to do something with each item. Usually I don't want to return anything.
    • .reduce/.reduceRight - I have an array, I need to make it into "one value". I'll have to check if I really need to use reduce for this.
  • Using regular expressions when you need "something with text" instead of parsing, simple string manipulation, or basic arithmetic, and so on.
  • Unformatted code.
1
answer
1
question
~167
people reached
  • Member for 4 years, 6 months
  • 13 profile views
  • Last seen 9 mins ago

Top tags (6)

Score 3
Posts 1
Posts % 50
Score 3
Posts 1
Score 3
Posts 1
Score 0
Posts 1
Score 0
Posts 1
Score 0
Posts 1

Top posts (2) All Questions Answers | Votes Newest

Badges (20)

Gold

1

Rarest

Silver

3

Rarest

Bronze

16

Rarest