Last active
May 11, 2021 17:13
-
-
Save NyaGarcia/eff7c4d3e918111b346a268e9185c2ae to your computer and use it in GitHub Desktop.
Refactoring a function to use guard clauses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function publishTweet(tweet) { | |
if (!isLoggedIn()) { | |
throw new Error('You need to log in before tweeting'); | |
} | |
if (!tweet) { | |
throw new Error("Your tweet is empty, can't publish it"); | |
} | |
if (!isTweetDoubleChecked()) { | |
throw new Error('Dont publish without double checking your tweet'); | |
} | |
tweetIt(tweet); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment