<commit_before>'use strict';

define(function() {

/**
 * Pending tasks.
 * @param {Object} store Object store
 * @constructor
 */
function Tasks(store) {
  this.store = store;
  this.tasks = this.store.init('tasks', {});
}

/**
 * Search for a task in the given section
 * @param {String} section Section name
 * @param {Object} search Array with search condition {name: value}
 */
Tasks.prototype.search = function(section, name, value) {
    if (!this.tasks.hasOwnProperty(section)) {
        return;
    }
    for(var i in this.tasks[section]) {
        var task = this.tasks[section][i];
        if (task[name] == value) {
            return task;
        }
    }
};

/**
 * Add a task into the given section
 * @param {String} section Section name
 * @param {Object} task Task to add
 */
Tasks.prototype.addTask = function(section, task) {
    if (!this.tasks.hasOwnProperty(section)) {
        this.tasks[section] = [];
    }
    task.seen = false;
    this.tasks[section].push(task);
    this.store.save();
};

/**
 * Remove a task from the given section
 * @param {String} section Section name
 * @param {Object} task Task to remove
 */
Tasks.prototype.removeTask = function(section, task) {
    if (!this.tasks.hasOwnProperty(section)) {
        return;
    }
    var idx = this.tasks[section].indexOf(task);
    this.tasks[section].splice(idx, 1);
    this.store.save();
};

/**
 * Get task objects for a section
 * @param {String} section Section name
 * @return {Object[]} List with the tasks.
 */
Tasks.prototype.getTasks = function(section) {
    if (this.tasks.hasOwnProperty(section)) {
        return this.tasks[section];
    }
    return [];
};

/**
 * Get the number of tasks in the given section
 * @param {String} section Section name or nothing to get all tasks
 * @return {Number} Number of tasks.
 */
Tasks.prototype.getOpenTasks = function(section) {
    if (section) {
        return self.tasks[section] ? self.tasks[section].length : 0;
    }
    var self = this;
    var nOpen = 0;
    Object.keys(this.tasks).forEach(function(section) {
        nOpen += self.tasks[section].length;
    });
    return nOpen;
};

/**
 * Clear all tasks
 */
Tasks.prototype.clear = function() {
    var self = this;
    Object.keys(this.tasks).forEach(function(section) {
        delete self.tasks[section];
    });
    this.store.save();
};

return Tasks;
});
<commit_msg>Fix remove task when the task doesn't exist.<commit_after>'use strict';

define(function() {

/**
 * Pending tasks.
 * @param {Object} store Object store
 * @constructor
 */
function Tasks(store) {
  this.store = store;
  this.tasks = this.store.init('tasks', {});
}

/**
 * Search for a task in the given section
 * @param {String} section Section name
 * @param {Object} search Array with search condition {name: value}
 */
Tasks.prototype.search = function(section, name, value) {
    if (!this.tasks.hasOwnProperty(section)) {
        return;
    }
    for(var i in this.tasks[section]) {
        var task = this.tasks[section][i];
        if (task[name] == value) {
            return task;
        }
    }
};

/**
 * Add a task into the given section
 * @param {String} section Section name
 * @param {Object} task Task to add
 */
Tasks.prototype.addTask = function(section, task) {
    if (!this.tasks.hasOwnProperty(section)) {
        this.tasks[section] = [];
    }
    task.seen = false;
    this.tasks[section].push(task);
    this.store.save();
};


/**
 * Remove a task from the given section
 * @param {String} section Section name
 * @param {Object} task Task to remove
 * @return true of false if the object was removed
 */
Tasks.prototype.removeTask = function(section, task) {
    if (!this.tasks.hasOwnProperty(section)) {
        return;
    }
    var idx = this.tasks[section].indexOf(task);
    if (idx > -1) {
        this.tasks[section].splice(idx, 1);
        this.store.save();
        return true;
    }
};

/**
 * Get task objects for a section
 * @param {String} section Section name
 * @return {Object[]} List with the tasks.
 */
Tasks.prototype.getTasks = function(section) {
    if (this.tasks.hasOwnProperty(section)) {
        return this.tasks[section];
    }
    return [];
};

/**
 * Get the number of tasks in the given section
 * @param {String} section Section name or nothing to get all tasks
 * @return {Number} Number of tasks.
 */
Tasks.prototype.getOpenTasks = function(section) {
    if (section) {
        return self.tasks[section] ? self.tasks[section].length : 0;
    }
    var self = this;
    var nOpen = 0;
    Object.keys(this.tasks).forEach(function(section) {
        nOpen += self.tasks[section].length;
    });
    return nOpen;
};

/**
 * Clear all tasks
 */
Tasks.prototype.clear = function() {
    var self = this;
    Object.keys(this.tasks).forEach(function(section) {
        delete self.tasks[section];
    });
    this.store.save();
};

return Tasks;
});

{'fraction_non_alphanumeric': 0.14573991031390135, 'fraction_numerical': 0.0014268242967794538, 'mean_word_length': 2.9130781499202554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3990357', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1496, 'n_words': 417}