Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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: ''}
];
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
You can’t perform that action at this time.