Created
June 22, 2019 04:24
-
-
Save jsmanifest/055072dfc1a40b0edc1eb76d1a1f0db2 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