Last active
July 7, 2018 17:32
-
-
Save merolhack/c814dea1f69c37965e8bbe2c5f998f35 to your computer and use it in GitHub Desktop.
ES6 Functional programming
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
const axios = require('axios'); | |
// Declare a method to consume the API | |
const getMeetups = (lon, lat) => axios | |
.post('https://safemeet-back-jmedcxhwdp.now.sh', { lon, lat }) | |
.then(({data}) => data); | |
// Call the method and get the name of each meetup | |
Promise.all([getMeetups(-103.4054534, 20.6737777), getMeetups(-99.1709761, 19.426063)]) | |
.then((myArray) => { | |
const gdl = myArray[0].events.map((element) => { | |
return `GDL: ${element.name}`; | |
}); | |
const cdmx = myArray[1].events.map((element) => { | |
return `CDMX: ${element.name}`; | |
}); | |
return [...gdl, ...cdmx]; | |
}) | |
.then((meetups) => { | |
meetups.forEach((name) => { | |
console.log('Name:', name); | |
}); | |
}); |
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
const emloyees = [ | |
{ | |
name: 'Juan', | |
salary: 7000 | |
}, | |
{ | |
name: 'Juan', | |
salary: 8000 | |
}, | |
{ | |
name: 'Juan', | |
salary: 9000 | |
} | |
].map((employee) => { | |
return {...employee, salary: employee.salary += 10000}; | |
}); | |
console.log('emloyees', emloyees); |
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
const filterArray = [1, 2, 3, 4, 5, 6, 7].filter((element) => { | |
return element > 3; | |
}); | |
console.log('filterArray', filterArray); |
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
const mapArray = [1, 2, 3, 4, 5, 6, 7].map((element) => { | |
return element * 3; | |
}); | |
console.log('mapArray', mapArray); | |
const mapString = ['Foo', 'Bar', 'Baz'].map((element) => { | |
return element.toUpperCase(); | |
}); | |
console.log('mapString', mapString); |
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
const reduceArray = [1, 2, 3, 4, 5, 6, 7].reduce((acumulador, element) => { | |
return acumulador + element; | |
}); | |
console.log('reduceArray', reduceArray); |
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
const someArray = [0, 2, 3, 4, 5, 6, 7].some((element) => { | |
return element === 1; | |
}); | |
console.log('someArray', someArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment