Last active
March 7, 2018 19:43
-
-
Save cbdallavalle/f7bbb4a2fea1f4f9555717fe670d8fa2 to your computer and use it in GitHub Desktop.
This file contains 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
Promises | |
1.testnum | |
testnum = (num) => { | |
if(num > 10) { | |
resolve(`${num} is greater than 10, success!`) | |
} else { | |
reject(Error(`${num} is less than 10, error!`) | |
} | |
} | |
2.makeAllCaps | |
makeAllCaps = (array) => { | |
return new Promise((resolve, reject) => { | |
if(array.every(value => typeof value === 'string')) { | |
const allCaps = array.map(value => value.toUpperCase()); | |
resolve(allCaps); | |
} else { | |
reject(Error('The array you passed in contained an element that was not a string')) | |
} | |
}) | |
} | |
sortWords = (array) => { | |
return new Promise ((resolve, reject) => { | |
resolve(array.sort()); | |
}) | |
} | |
Writen Questions | |
1. .then is used to allow developers to manipulate or use the value a promise resolves. .catch is used for error handling | |
2. Anytime asynchronous js code is being run | |
3. Node, Q, Bluebird |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment