<commit_before>const app_root_path = require('app-root-path').path;
const _ = require('lodash');
const shortid = require('shortid');
const helpers = require(app_root_path + '/helpers/helpers.js');

/**
 * The Group class
 */
var Group = {};

/**
 * Initialize with a name and a description for the group.
 * Auto-generates a unique id.
 * Returns the `this` reference to the Group object.
 * @param  {!string} name
 * @param  {string} description
 * @return {Group}
 */
Group.init = function(name, description) {
    helpers.assert(!_.isEmpty(name), 'group name should not be empty');
    
    this.name = name;
    this.description = description;
    
    this.userMap = new Map();
    this.messages = [];
    this.groupCreator = null; // TODO: once we have login and user identification support

    this.id = shortid.generate();

    return this;
};

/**
 * Returns the list of users ids as an array
 * @return {Array<string>}
 */
Group.getUserIds = function() {
    return [...this.userMap.keys()];
};

/**
 * Return the list of users as an array
 * @return {Array<User>}
 */
Group.getUsers = function() {
    return [...this.userMap.values()];
};

/**
 * Add a single user or an array of users to the group
 * @param {User|Array<User>} users
 */
Group.addUsers = function(users) {
    if (!Array.isArray(users)) {
        users = [users]
    }

    users.filter(function(user) {
        return !this.userMap.has(user.id);
    }).forEach(function(user) {
        this.userMap.set(user.id, user);
    });
};

/**
 * Adds a single Message or an array of Messages to the group
 * Returns the number of messages added
 * @param {Message|Array<Message>} messages
 * @return {number}
 */
Group.addMessages = function(messages) {
    if (Array.isArray(messages)) {
        messages = [messages];
    }

    return Array.prototype.push.apply(this.messages, messages);
};

// See `toJSON()` section at:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
// Might be useful in the steps leading up storing into database
// That is, we only need to store the ids of the users in this group into the db, not the User objects themselves
Group.toJSON = function() {
    return {
        name: this.name,
        description: this.description,
        usersIds: this.getUserIds()
        // TODO messages and more...
    }
};

module.exports = Group;
<commit_msg>Fix another small error<commit_after>const app_root_path = require('app-root-path').path;
const _ = require('lodash');
const shortid = require('shortid');
const helpers = require(app_root_path + '/helpers/helpers.js');

/**
 * The Group class
 */
var Group = {};

/**
 * Initialize with a name and a description for the group.
 * Auto-generates a unique id.
 * Returns the `this` reference to the Group object.
 * @param  {!string} name
 * @param  {string} description
 * @return {Group}
 */
Group.init = function(name, description) {
    helpers.assert(!_.isEmpty(name), 'group name should not be empty');
    
    this.name = name;
    this.description = description;
    
    this.userMap = new Map();
    this.messages = [];
    this.groupCreator = null; // TODO: once we have login and user identification support

    this.id = shortid.generate();

    return this;
};

/**
 * Returns the list of users ids as an array
 * @return {Array<string>}
 */
Group.getUserIds = function() {
    return [...this.userMap.keys()];
};

/**
 * Return the list of users as an array
 * @return {Array<User>}
 */
Group.getUsers = function() {
    return [...this.userMap.values()];
};

/**
 * Add a single user or an array of users to the group
 * @param {User|Array<User>} users
 */
Group.addUsers = function(users) {
    if (!Array.isArray(users)) {
        users = [users]
    }

    users.filter(function(user) {
        return !this.userMap.has(user.id);
    }).forEach(function(user) {
        this.userMap.set(user.id, user);
    });
};

/**
 * Adds a single Message or an array of Messages to the group
 * Returns the number of messages added
 * @param {Message|Array<Message>} messages
 * @return {number}
 */
Group.addMessages = function(messages) {
    if (!Array.isArray(messages)) {
        messages = [messages];
    }

    return Array.prototype.push.apply(this.messages, messages);
};

// See `toJSON()` section at:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
// Might be useful in the steps leading up storing into database
// That is, we only need to store the ids of the users in this group into the db, not the User objects themselves
Group.toJSON = function() {
    return {
        name: this.name,
        description: this.description,
        usersIds: this.getUserIds()
        // TODO messages and more...
    }
};

module.exports = Group;

{'fraction_non_alphanumeric': 0.14030347121180628, 'fraction_numerical': 0.0, 'mean_word_length': 3.0918367346938775, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '4462885', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1443, 'n_words': 447}