Last active
June 23, 2017 22:08
-
-
Save GuyMograbi/fed87b447543a6eb9786ae5fb3c7945c to your computer and use it in GitHub Desktop.
improve javascript stacktrace
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
function getName () { | |
return new Promise((resolve)=>{ | |
resolve({status:500}); | |
}).then((response) => { // validate output | |
if (response.status === 500){ | |
throw new Error('request to get name has failed'); | |
}else{ | |
return response; | |
} | |
}); // emulate http call | |
} | |
function getFullName (info) { | |
if (!info){ // validate input | |
throw new Error('info is missing'); | |
} | |
return new Promise((resolve) => { | |
resolve(info.firstName + ' ' + info.lastName) | |
}) | |
} | |
function countLetter(fullName, letter){ | |
if (!fullName || !letter){ // validate input | |
throw new Error('letter or fullName is undefined fullName=[' + fullName + '] letter=[' + letter + ']'); | |
} | |
return new Promise((resolve)=>{ | |
resolve(fullName.split(letter).length-1); | |
}) | |
} | |
function countLetters (fullName) { | |
if (!fullName){ // validate input | |
throw new Error('fullName is missing'); | |
} | |
const result = {}; | |
return Promise.all('abcdefghijklmnopqrstuvwxyz'.split('').map((char)=>{ | |
countLetter(fullName, char).then((count)=>{ | |
result[char] = count; | |
}) | |
})).then(()=>result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment