Add exercice about 'if' (#40)
* ✨ add bonus (about if) in exo1 * ♻️ improve bonus * 🔥 remove not clear exercice * ♻️ better bonus explanations * ♻️ spaces
This commit is contained in:
parent
a499a93364
commit
eb34020b8e
1 changed files with 11 additions and 0 deletions
|
@ -27,6 +27,17 @@ export const divide = (a: number, b: number): number => {
|
|||
export const safeDivide: (a: number, b: number) => Option<number> =
|
||||
unimplemented;
|
||||
|
||||
|
||||
// You probably wrote `safeDivide` using `if` statements and it's perfectly valid!
|
||||
// There are ways to not use `if` statements.
|
||||
// Keep in mind that extracting small functions out of pipes and using `if` statements in them
|
||||
// is perfectly fine and is sometimes more readable than not using `if`.
|
||||
//
|
||||
// BONUS: Try now to re-write `safeDivide` without any `if`
|
||||
//
|
||||
// HINT: Have a look at `fromPredicate` constructor
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// EITHER //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Reference in a new issue