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
| module.exports = { | |
| /** | |
| * Function to verify all validations | |
| * @param {...any} paramsRaw An array of validation results, | |
| * Values can either be `true` or `error string`. | |
| */ | |
| all: async function (...paramsRaw) { | |
| const params = await Promise.all(paramsRaw) | |
| const error = params | |
| .filter(val => typeof val === 'string')[0] |
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 readFile(path) { | |
| return new Promise((resolve, reject) => { | |
| fs.readFile(path, (err, data) => { | |
| if (err) { | |
| return reject(err) | |
| } | |
| return resolve(data) | |
| }) | |
| }) | |
| } |
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 buyBread (input) { | |
| return gotoStore(input) | |
| .then(() => { | |
| return buyBrownBread(input) | |
| .catch(() => buyWhiteBread(input)) | |
| }) | |
| } |
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 showFavouriteArticles () { | |
| getUser() | |
| .then(user => getFavouriteArticles(user)) | |
| .then(articles => showArticles(articles)) | |
| .catch(err => notifyError(err)) | |
| } |
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 buyBread (input, callback) { | |
| gotoStore(input, (storeErr, storeResponse) => { | |
| if (storeErr) { | |
| return callback(storeErr, null) | |
| } | |
| buyBrownBread(input, (brownBreadErr, brownBreadResponse) => { | |
| if (brownBreadErr) { | |
| buyWhiteBread(input, (whiteBreadErr, whiteBreadResponse) => { | |
| if (whiteBreadErr) { | |
| return callback(whiteBreadErr, null) |
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 buyBread (input, callback) { | |
| gotoStore(input, (storeErr, storeResponse) => { | |
| if (storeErr) { | |
| return callback(Error('Store is unavailable'), null) | |
| } | |
| buyBrownBread(input, (brownBreadErr, brownBreadResponse) => { | |
| // if unable to buy brown bread, buy white bread | |
| if (brownBreadErr) { | |
| buyWhiteBread(input, (whiteBreadErr, whiteBreadResponse) => { | |
| if (whiteBreadErr) { |
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
| // Reverse only the letters of words in a sentence | |
| // A helper function to reverse words | |
| const reverseWord = str => str.split('').reverse().join('') | |
| // Actual function | |
| const reverseLettersInSentence = sentence => sentence | |
| .split(' ') | |
| .map(reverseWord) | |
| .join(' ') |
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 flatten = arr => arr | |
| .reduce((a, b) => a.concat(b)) | |
| // Execution | |
| flatten([ | |
| [1, 2, 3], | |
| [4, 5], | |
| [6] | |
| ]) |
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 positiveSum = arr => { | |
| let sum = 0 | |
| let i = 0 | |
| let ii = arr.length | |
| for (i = 0; i < ii; ++i) { | |
| if (arr[i] > 0) { | |
| sum += arr[i] | |
| } | |
| } | |
| } |
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 somefunc = string => string | |
| .split(/* Something */) | |
| .map(/* Something */) | |
| .filter(/* Something */) |
NewerOlder