Reading Notes
Array.map() takes an array and creates a new array with the results of a function called on every element of the original array
Array.reduce() produces a single result from running a function on each element of a given array
Superagent()
.then
syntax:
let getCharacters = () => {
superagent.get (`https://swapi.dev/api/people`)
.then( data => {
console.log(`{ ${data.body.results[0].name} : ${data.body.results[0].url} }`);
})
.catch(err => {
console.error('Something broke:', err);
})
}
getCharacters();
async function getCityData () {
let cities = ['Houston', 'Duvall', 'Carnation', 'Seattle', 'Tunis', 'Bellingham'];
for (let i=0; i<cities.length; i++){
try {
let results = await superagent.get(`https://geocode.xyz/${cities[i]}?json=1`)
console.log(cities[i], ' --> Latitude: ', results.body.latt, ' Longitude: ', results.body.longt);
}
catch { err => console.log(err)};
}
}
getCityData();
Promise a promise allows an asynchronous to provide a temporary result inline which is then defined when the promise is resolved
Callback Functions not all callback functions are asynchronous, typically asynchronous functions pull in information from outside processes or resources