Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Add suggestions for Leap on Javascript #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tracks/javascript/exercises/leap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Reasonable solutions

```javascript
module.exports = {
isLeap(year) {
if (this.year % 4 !== 0) return false

if (this.year % 100 !== 0) return true

if (this.year % 100 === 0 && this.year % 400 === 0) return true

return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a talking point would be that if statements that return true and false probably shouldn't because conditional statements are by definition true or false.

}
```

### Common suggestions

- For solutions that have more than one exit point, suggest trying to use a single
exit point while maintaining legibility. It could be done by aggregating all
conditionals in one and creating a temp var with a legible name for each.

- Creating a helper function that checks if a number is divisible might also be
a good idea. This would help with the first point and keep the logic readable.
[Here is a good example of it](https://exercism.io/tracks/javascript/exercises/leap/solutions/caa4742c2be14884848044f9bcfbb775)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the example here, no if statement because the conditional statements can speak for themselves.


### Talking points

- Although this exercise is quite simple it is worth talking about the dangers of
having functions with a lot of branching and specially when they lead to exit points.

- If there is a boolean check that returns `true` or `false` then just returning the
result of the boolean operation might achieve the same result.