Skip to content

Commit 99bf64c

Browse files
committed
docs: replacing if operators w/ ternaries
1 parent 39412da commit 99bf64c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,31 @@ Whenever a function calls itself, creating a loop.
109109
1) Countdown
110110

111111
```javascript
112-
const countdown = num => {
113-
if (num > 0) {
114-
console.log(num);
115-
countdown(num - 1);
116-
}
117-
}
118112

113+
const count = num => {
114+
console.log(num)
115+
num < 1
116+
? num
117+
: count(num - 1)
118+
}
119119
countdown(5);
120120
/*
121121
5
122122
4
123123
3
124124
2
125125
1
126+
0
126127
*/
127128
```
128129

129130
2) Factorial
130131

131132
```javascript
132-
const factorial = num => {
133-
if (num <= 0) {
134-
return 1;
135-
} else {
136-
return (num * factorial(num - 1));
137-
}
133+
const factorial = (num) =>
134+
num <= 0
135+
? 1
136+
: n * factorial(num - 1)
138137
}
139138

140139
factorial(5);

0 commit comments

Comments
 (0)