Last active
June 23, 2017 22:10
-
-
Save GuyMograbi/b694ec10d52295647c37ee8e51a021c2 to your computer and use it in GitHub Desktop.
original code for improve-stack-post
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}); | |
}); // 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