{"size": 1976, "ext": "js", "max_stars_repo_path": "js/factions.js", "max_stars_repo_name": "Partinez/console-drifter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/factions.js", "max_issues_repo_name": "Partinez/console-drifter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/factions.js", "max_forks_repo_name": "Partinez/console-drifter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0975609756, "max_line_length": 111, "alphanum_fraction": 0.6837044534}
function Faction(name, leader, joinCond, leaveCond, support, opposite, perk) {
  this.name = name;
  this.leader = leader;
  if (joinCond !== null) {
    this.joinCondStat = joinCond.stat;
    this.joinCondLevel = joinCond.level;
    this.joinCondValue = joinCond.value;
  }
  if (leaveCond !== null) {
    this.leaveCondStat = leaveCond.stat;
    this.leaveCondLevel = leaveCond.level;
    this.leaveCondValue = leaveCond.value;
  }

  this.support = support;
  this.opposite = opposite;
  this.members = [];
  this.perkProgress = 0;
  this.perk = perk;
  this.news = {};
}

Faction.prototype.newLeader = function(citizen) {
  if (this.isMember(citizen)) {
    this.leader = leader;
    return true
  } else {
    return false
  }

}

Faction.prototype.memberCount = function() {
  return this.members.length;
}

Faction.prototype.isMember = function(citizen) {
  if (isIn(citizen, this.members)) {
    return true
  } else {
    return false
  }
}

Faction.prototype.addMember = function(citizen) {
  if (this.isMember(citizen)) {
    return false
  } else {
    this.members.push(citizen);
    citizen.factions.push(this.name);
    console.log('Citizen has joined a faction')
    return this.memberCount()
  }
}
Faction.prototype.addMembers = function(list) {
  list.forEach(function(citizen){
    this.addMember(citizen)
  }, this)
  return this.memberCount()
}
Faction.prototype.removeMembers = function(list) {
  list.forEach(function(citizen){
    this.removeMember(citizen)
  }, this)
  return this.memberCount()
}


Faction.prototype.removeMember = function(citizen) { //NOTE if leader, set new leader, if last, delete progress
  console.log('Remove');
  if (this.isMember(citizen)) {
    var index = this.members.indexOf(citizen);
    this.members.splice(index,1);
    var index = citizen.factions.indexOf(this.name);
    citizen.factions.splice(index,1);
    console.log('Citizen has left a faction')
    return this.memberCount()
  } else {
    return false
  }
}
