Created
August 13, 2018 00:16
-
-
Save jeremiahjstanley/f884250bf631e604876c5c972ee12d1d to your computer and use it in GitHub Desktop.
Promises Practice
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
const makeAllCaps = (words) => { | |
return new Promise((resolve, reject) => { | |
if (words.every((checkWord)) { | |
resolve(words.map(word => word.toUpperCase())) | |
} else { | |
reject('Invalid entry') | |
} | |
}) | |
}; | |
const sortWords = (words) => { | |
return new Promise((resolve, reject) => { | |
resolve(words.sort((a, b) => a - b)) | |
}) | |
}; | |
const checkWord = (word) => { | |
return Object.isString(word) | |
} | |
const greek = ['alpha', 'beta', 'gamma'] | |
makeAllCaps(greek) | |
.then(words => sortWords(words)) | |
.then(result => console.log(result)) | |
.catch(error => console.log(error)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment