Created
June 22, 2019 04:23
-
-
Save jsmanifest/82bac25a3ce257c3680837ab07155781 to your computer and use it in GitHub Desktop.
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
import axios from 'axios' | |
const getFrogs = async (params) => { | |
try { | |
const response = await axios.get( | |
'https://frogs-and-their-tongues.com', | |
params, | |
) | |
const frogs = response.data.result | |
return frogs | |
} catch (error) { | |
throw error | |
} | |
} | |
const calcAverageWidthOfTongues = async (params) => { | |
try { | |
const frogs = await getFrogs(params) | |
const tongueWidths = frogs.reduce((sum, frog) => { | |
return sum + frog.tongueWidth | |
}, 0) | |
const averageWidth = tongueWidths / frogs.length | |
return averageWidth | |
} catch (error) { | |
throw error | |
} | |
} | |
calcAverageWidthOfTongues({ | |
username: 'bob', | |
password: 'the_builder100', | |
}) | |
.then((result) => { | |
console.log(result) | |
}) | |
.catch((error) => { | |
console.error(error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment