Created
June 10, 2016 00:15
-
-
Save dvidsilva/52922ef281a921daa1f4838ce391f083 to your computer and use it in GitHub Desktop.
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
var movies = [ | |
{ | |
title: 'titanic', year: 2000 | |
}, | |
{ | |
title: 'robocop', year: 1990 | |
}]; | |
var result = movies.map(function (movie) { | |
return movie.title + ' came out ' + (2016 - movie.year) + ' years ago'; | |
}); | |
var products = [ | |
{name: 'coke', price: 1, tax: 0.9}, | |
{name: 'pepsi', price: 1.3, tax: 0.99}, | |
{name: 'pizza', price: 23, tax: 3} | |
] | |
var result = products.map(function (product) { | |
return '' + product.name + ' is : ' + (product.price + product.tax); | |
}); | |
var people = [ | |
{first_name: 'david', last_name: 'silva'}, | |
{first_name: 'jenn', last_name: 'Lê'} | |
]; | |
var result = people.map(function (person) { | |
return 'full name is: ' + person.first_name + ' ' + person.last_name; | |
}); | |
var products = [ | |
{name: 'coke', price: 1, tax: 0.9}, | |
{name: 'pepsi', price: 1.3, tax: 0.99}, | |
{name: 'pizza', price: 23, tax: 3}, | |
{name: 'burrito', price: 5, tax: 2} | |
]; | |
var result = products.filter(function (product) { | |
if (product.price > 3) { | |
return true; | |
} | |
return false; | |
}).map(function (product) { | |
return '' + product.name + ' is : ' + (product.price + product.tax); | |
}); | |
var products = [ | |
{ | |
name: 'drinks', | |
items: [ | |
{name: 'coke', price: 1, tax: 0.9}, | |
{name: 'pepsi', price: 1.3, tax: 0.99}] | |
}, { | |
name: 'foods', | |
items:[ | |
{name: 'pizza', price: 23, tax: 3}, | |
{name: 'burrito', price: 5, tax: 2}] | |
}]; | |
var result = products.map(function(category) { | |
return { | |
name: category.name, | |
items: category.items.map(function (product) { | |
return '' + product.name + ' is: ' + (product.price + product.tax); | |
}) | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment