peterschussheim
10/13/2016 - 1:44 PM

filter

filter

// see console for output!

const lessons = [
    {
        title: 'Javascript Arrays in Depth - join',
        views: 960,
        tags: ['array', 'join']
    },
    {
        title: 'Javascript Arrays in Depth - concat',
        views: 1050,
        tags: ['array', 'concat']
    },
    {
        title: 'Javascript Arrays in Depth - slice',
        views: 2503,
        tags: ['array', 'slice']
    },
    {
        title: 'Javascript Functions in Depth - bind',
        views: 2500,
        tags: ['functions', 'bind']
    }
];

const minViews = 1000;
const searchTerm = 'array';
var filtered = lessons
	.filter(x => x.tags.indexOf(searchTerm) > -1) ///searchTerm > -1 means term is present in array.
	.filter(x => x.views > minViews)
	.sort((a, b) => b.views - a.views)
	.map(x => ` <li>${x.title}</li>`)
	.join('\n');

filter

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.