Javascript ES6 .filter(); with shorthand
const companies = {
{name: "Company One", category: "Finance", start: 1981, end: 2003},
{name: "Company One", category: "Finance", start: 1992, end: 2008},
{name: "Company One", category: "Finance", start: 1999, end: 2007},
{name: "Company One", category: "Finance", start: 1989, end: 2010},
{name: "Company One", category: "Finance", start: 2009, end: 2014},
{name: "Company One", category: "Finance", start: 1987, end: 2010},
{name: "Company One", category: "Finance", start: 1986, end: 1996},
{name: "Company One", category: "Finance", start: 2011, end: 2016},
{name: "Company One", category: "Finance", start: 1981, end: 1989}
}
const ages = [33, 12, 20, 16, 5, 54, 21, 44, 61, 13, 15, 45, 25, 64, 32];
// Filter retail companies
const retailCompanies = comapanies.filter(function(company) {
if(company.catgory === 'Retail') {
return true;
}
})
const retailComanies = companies.filter(company => company.category === 'Retail');
// get 80's companies
const eightiesCompanies = companies.filter(company => (company.start >= 1908 && company.start < 1990));
console.log(eightiesCompanies);
// Get companies that lasted 10 years or more
const lastedTenYears = companies.filter(company => (company.end - company.start > 10));
console.log(lastedTenYears);