Simple example of how to create an ES5 Promise.
// A. If no dirPath exists, use a default.
var dirPath = (dirPath) ? dirPath: `${process.cwd()}/html/raw/`;
let promise = await new Promise( async (resolve, reject) => {
// B. Prepend absolute directory path to the beginning of each array element
let array = fs.readdirSync(dirPath).map(filePaths => { return `${dirPath}${filePaths}` })
// C. Remove hidden files
.filter(Utils.isNotUnixHiddenPath)
// D. Remove directories and other non-files.
.filter(Utils.isFile)
// E. Success
resolve( array );
})
.then( response => { return response } )
.catch( err => console.error(err) );
return promise;
Finance: Calculating Annuities using ES6
Annuities are cool. They're fixed payments over a period of time. If you're living in England, there's another financial product called a...
Statistics: Calculating Probabilities using ES6
Suppose you wanted to calculate the percentage of men that weigh inbetween 140 and 170 lbs. This is possible if you carry a few data points such as...
Subscribe to new posts
Processing your application
Please check your inbox and click the link to confirm your subscription
There was an error sending the email