To be, or not to be, that is the question
Translating it into code, we get
theQuestion = 2b || !2b
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
.map()(or any other array method like
.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
.mapbut 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.
.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.
Member for 4 years, 7 months
0 profile views
Last seen Oct 18 at 11:03
- Stack Overflow 9.3k 9.3k 66 gold badges2626 silver badges3838 bronze badges
- Worldbuilding 1.4k 1.4k 11 gold badge77 silver badges2121 bronze badges
- Science Fiction & Fantasy 771 771 66 silver badges1515 bronze badges
- Code Review 413 413 33 silver badges1010 bronze badges
- Information Security 322 322 33 silver badges99 bronze badges
- View network profile →
Top network posts
- 40 Origin of genies (from lamps) having a three wish limit?
- 18 Short story about people being sacrificed during a flight
- 17 Player class for RPG/DND type game
- 17 What could an "<img src=" XSS do?
- 15 How can an eldritch abomination hide its true form in public?
- View more network posts →