Skip to content

Commit 5d882d9

Browse files
committed
Improvement on email client function
In the section "Functions should do one thing" this change uses the Array.filter method to get the active clients, then emailing those with the forEach loop.
1 parent ddd0181 commit 5d882d9

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,9 @@ function emailClients(clients) {
274274
**Good**:
275275
```javascript
276276
function emailClients(clients) {
277-
clients.forEach(client => {
278-
emailClientIfNeeded(client);
279-
});
280-
}
281-
282-
function emailClientIfNeeded(client) {
283-
if (isClientActive(client)) {
284-
email(client);
285-
}
277+
clients
278+
.filter(isClientActive)
279+
.forEach(email);
286280
}
287281

288282
function isClientActive(client) {

0 commit comments

Comments
 (0)