<commit_before>'use strict';

var _ = require('underscore');
var Collection = require('./collection');
var Variable = require('./variable');

function VariableCollection(args) {
  Collection.call(this, {
    SubCollectionItem: Variable,
    items: args.items
  });
}
VariableCollection.prototype = Object.create(Collection.prototype);

// Return true if a variable with the given name does not exist in the
// collection; otherwise, return false
VariableCollection.prototype.checkNameAvailability = function (variableName) {
  return !_.some(this.items, function (variable) {
    return (variable.name === variableName);
  });
};

// Transform all possible permutations of true/false values for this collection
// of variables using the provided callback
VariableCollection.prototype.mapPermutations = function (callback) {
  var variables = this;
  // An object where each key is a variable name and each value is a boolean
  // representing the current value of that variable
  var currentVarValues = _.object(variables.map(function (variable) {
    // Initialize all variable values to false
    return [variable.name, false];
  }));
  // If n corresponds to the number of variables, then there will always be 2^n
  // permutations to generate
  return _.times(Math.pow(2, variables.length), function (rowIndex) {
    variables.forEach(function (variable, varIndex) {
      // Alternate variable values as needed (but not on the first permutation)
      if (rowIndex % Math.pow(2, variables.length - varIndex - 1) === 0 && rowIndex !== 0) {
        currentVarValues[variable.name] = !currentVarValues[variable.name];
      }
    });
    return callback(currentVarValues);
  });
};

// Get the next available variable name for a new variable (to insert next to
// the given variable)
VariableCollection.prototype.getNextVariableName = function (variable) {
  // Create a list of variable names already in use
  var variableCharCodes = this.map(function (variable) {
    return variable.name.charCodeAt(0);
  });
  // Look for the next letter that isn't already in use
  var nextVarCharCode = variable.name.charCodeAt(0);
  do {
    nextVarCharCode += 1;
    // Wrap variable name around alphabet if necessary (e.g. 'z' wraps around to
    // 'z')
    if (nextVarCharCode === 91 || nextVarCharCode === 123) {
      nextVarCharCode = nextVarCharCode - 26;
    }
  } while (variableCharCodes.indexOf(nextVarCharCode) !== -1);
  return String.fromCharCode(nextVarCharCode);
};

module.exports = VariableCollection;<commit_msg>Correct typo in getNextVariableName comment<commit_after>'use strict';

var _ = require('underscore');
var Collection = require('./collection');
var Variable = require('./variable');

function VariableCollection(args) {
  Collection.call(this, {
    SubCollectionItem: Variable,
    items: args.items
  });
}
VariableCollection.prototype = Object.create(Collection.prototype);

// Return true if a variable with the given name does not exist in the
// collection; otherwise, return false
VariableCollection.prototype.checkNameAvailability = function (variableName) {
  return !_.some(this.items, function (variable) {
    return (variable.name === variableName);
  });
};

// Transform all possible permutations of true/false values for this collection
// of variables using the provided callback
VariableCollection.prototype.mapPermutations = function (callback) {
  var variables = this;
  // An object where each key is a variable name and each value is a boolean
  // representing the current value of that variable
  var currentVarValues = _.object(variables.map(function (variable) {
    // Initialize all variable values to false
    return [variable.name, false];
  }));
  // If n corresponds to the number of variables, then there will always be 2^n
  // permutations to generate
  return _.times(Math.pow(2, variables.length), function (rowIndex) {
    variables.forEach(function (variable, varIndex) {
      // Alternate variable values as needed (but not on the first permutation)
      if (rowIndex % Math.pow(2, variables.length - varIndex - 1) === 0 && rowIndex !== 0) {
        currentVarValues[variable.name] = !currentVarValues[variable.name];
      }
    });
    return callback(currentVarValues);
  });
};

// Get the next available variable name for a new variable (to insert next to
// the given variable)
VariableCollection.prototype.getNextVariableName = function (variable) {
  // Create a list of variable names already in use
  var variableCharCodes = this.map(function (variable) {
    return variable.name.charCodeAt(0);
  });
  // Look for the next letter that isn't already in use
  var nextVarCharCode = variable.name.charCodeAt(0);
  do {
    nextVarCharCode += 1;
    // Wrap variable name around alphabet if necessary (e.g. 'z' wraps around to
    // 'a')
    if (nextVarCharCode === 91 || nextVarCharCode === 123) {
      nextVarCharCode = nextVarCharCode - 26;
    }
  } while (variableCharCodes.indexOf(nextVarCharCode) !== -1);
  return String.fromCharCode(nextVarCharCode);
};

module.exports = VariableCollection;
{'fraction_non_alphanumeric': 0.10752264671130367, 'fraction_numerical': 0.00669554942890902, 'mean_word_length': 3.9262851600387974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4140180', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1341, 'n_words': 467}