Skip to content

Instantly share code, notes, and snippets.

@GuyMograbi
Last active June 23, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuyMograbi/b694ec10d52295647c37ee8e51a021c2 to your computer and use it in GitHub Desktop.
Save GuyMograbi/b694ec10d52295647c37ee8e51a021c2 to your computer and use it in GitHub Desktop.
original code for improve-stack-post
function getName () {
return new Promise((resolve)=>{
resolve({status:500});
}); // emulate http call
}
function getFullName (info) {
return new Promise((resolve) => {
resolve(info.firstName + ' ' + info.lastName)
})
}
function countLetter(fullName, letter){
return new Promise((resolve)=>{
resolve(fullName.split(letter).length-1);
})
}
function countLetters (fullName) {
const result = {};
return Promise.all('abcdefghijklmnopqrstuvwxyz'.split('').map((char)=>{
countLetter(fullName, char).then((count)=>{
result[char] = count;
})
})).then(()=>result);
}
function analyzeName () {
let result = {};
return getName().then(({data}) => {
result.name = data;
getFullName(data);
}).then((fullName) => {
result.fullName = fullName;
return countLetters(fullName)
}).then((count)=>{
result.count = count;
}).then(()=>{
return result
})
}
analyzeName().then((result) => {
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment