Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 22, 2019 04:23
Show Gist options
  • Save jsmanifest/82bac25a3ce257c3680837ab07155781 to your computer and use it in GitHub Desktop.
Save jsmanifest/82bac25a3ce257c3680837ab07155781 to your computer and use it in GitHub Desktop.
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