Skip to content

Instantly share code, notes, and snippets.

@merolhack
Last active July 7, 2018 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merolhack/c814dea1f69c37965e8bbe2c5f998f35 to your computer and use it in GitHub Desktop.
Save merolhack/c814dea1f69c37965e8bbe2c5f998f35 to your computer and use it in GitHub Desktop.
ES6 Functional programming
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);
});
});
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);
const filterArray = [1, 2, 3, 4, 5, 6, 7].filter((element) => {
return element > 3;
});
console.log('filterArray', filterArray);
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);
const reduceArray = [1, 2, 3, 4, 5, 6, 7].reduce((acumulador, element) => {
return acumulador + element;
});
console.log('reduceArray', reduceArray);
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