Skip to content

Commit c1b5e8f

Browse files
JonathanBruceKent C. Dodds
authored andcommitted
Clamp remove value to 0 (#15)
If the message array length equals 0, the second slice param becomes -1 which refills the messages array up to the first index.
1 parent 41146ca commit c1b5e8f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/exercises/05.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Usage() {
6060
const addMessage = () =>
6161
setMessages(allMessages.slice(0, messages.length + 1))
6262
const removeMessage = () =>
63-
setMessages(allMessages.slice(0, messages.length - 1))
63+
setMessages(allMessages.slice(0, Math.max(0, messages.length - 1)))
6464

6565
return (
6666
<div>

0 commit comments

Comments
 (0)