peterschussheim
10/13/2016 - 9:40 PM

some

some

///some accepts a function and calls the function on each element, yielding a boolean.\\\\Provides a simple yes or no answer when querrying an array.

var tasks = [
    {
        title: 'Do laundry',
        completed: true
    },
    {
        title: 'Feed the cat',
        completed: true
    },
    {
        title: 'Watch the array lessons on egghead.io',
        completed: true
    }
];

// var list = document.querySelector('.task-list');
// list.classList.add(tasks.some(task => task.completed === false)
//     ? 'task-list--uncompleted'
//     : 'task-list--completed'
// );

// list.innerHTML = tasks
// 	.map(x => x.completed ? `<s>${x.title}</s>` : x.title)
// 	.map(x => `<li>${x}</li>`)
// 	.join('');

function addTask(title) {
    if (tasks.some(task => task.title === title)) {
    	return;
    }
    tasks.push({title: title, completed: false});
}

////Using\\\`some\\\` to guard against duplicate entries.
addTask('Feed the cat');

tasks

some

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

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