<commit_before>'use strict'

Creep.getRole = function (roleName) {
  var Role = require('roles_' + roleName)
  return new Role()
}

Creep.prototype.getRole = function () {
  // If the creep role isn't in memory grab it based off of the name
  var roleType = this.memory.role ? this.memory.role : this.name.split('_')[0]
  return Creep.getRole(roleType)
}

Creep.getCost = function (parts) {
  if (typeof parts === 'string') {
    if (BODYPART_COST[parts]) {
      return BODYPART_COST[parts]
    }
  }
  var cost = 0
  _.forEach(parts, function (part) {
    cost += BODYPART_COST[part]
  })
  return cost
}

Creep.buildFromTemplate = function (template, energy) {
  var parts = []
  while (energy > 0 && parts.length < 50) {
    var next = template[parts.length % template.length]
    if (BODYPART_COST[next] > energy) {
      break
    }
    energy -= BODYPART_COST[next]
    parts.push(next)
  }
  return parts
}<commit_msg>When determining role from creep name, only build as big an array as we need in JS.<commit_after>'use strict'

Creep.getRole = function (roleName) {
  var Role = require('roles_' + roleName)
  return new Role()
}

Creep.prototype.getRole = function () {
  // If the creep role isn't in memory grab it based off of the name
  var roleType = this.memory.role ? this.memory.role : this.name.split('_', 1)[0]
  return Creep.getRole(roleType)
}

Creep.getCost = function (parts) {
  if (typeof parts === 'string') {
    if (BODYPART_COST[parts]) {
      return BODYPART_COST[parts]
    }
  }
  var cost = 0
  _.forEach(parts, function (part) {
    cost += BODYPART_COST[part]
  })
  return cost
}

Creep.buildFromTemplate = function (template, energy) {
  var parts = []
  while (energy > 0 && parts.length < 50) {
    var next = template[parts.length % template.length]
    if (BODYPART_COST[next] > energy) {
      break
    }
    energy -= BODYPART_COST[next]
    parts.push(next)
  }
  return parts
}
{'fraction_non_alphanumeric': 0.12831168831168832, 'fraction_numerical': 0.005714285714285714, 'mean_word_length': 3.232967032967033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3701862', 'n_tokens_mistral': 694, 'n_tokens_neox': 673, 'n_words': 177}