var utils = require("./utils");

function CodeManager() {
    this.codes = [];
    this.currentSession = -1;
    this.codesGenerated = false;
}

CodeManager.prototype.nextSession = function() {
    if (this.codes[this.currentSession + 1]) {
        this.currentSession++;
    } else if (this.currentSession === -1) {
        throw "No codes generated";
    } else {
        this.currentSession = -1;
        throw "Out of generated codes";
    }
};

CodeManager.prototype.generateCodes = function(nbrOfUsers, nbrOfCodesPerUser, lengthOfCodes) {
    this.codesGenerated = true;
    return this.codes = utils.generateCodes(nbrOfUsers, nbrOfCodesPerUser, lengthOfCodes);
};

CodeManager.prototype.currentSessionCodes = function() {
    return this.codes[this.currentSession];
};

CodeManager.prototype.isValidCode = function(code) {
    return this.currentSessionCodes().indexOf(code) !== -1;
};

CodeManager.prototype.invalidateCode = function(code) {
    var previousLength = this.currentSessionCodes().length;
    this.codes[this.currentSession] = this.currentSessionCodes().filter(function(sessionCode) {
        return sessionCode !== code;
    });

    return previousLength - 1 === this.currentSessionCodes().length;
};

module.exports = CodeManager;

@@ -191,24 +191,25 @@
 ) %7B%0A    if (
+!
 this.codes%5Bt
@@ -210,78 +210,67 @@
 odes
-%5Bthis.currentSession + 1%5D) %7B%0A        this.currentSession++
+Generated) %7B%0A        throw %22No codes generated%22
 ;%0A    %7D
- else
+%0A%0A   
  if 
@@ -271,24 +271,35 @@
    if (this.
+codes%5Bthis.
 currentSessi
@@ -305,14 +305,12 @@
 ion 
-=== -1
++ 1%5D
 ) %7B%0A
@@ -323,32 +323,27 @@
   th
-row %22No codes generated%22
+is.currentSession++
 ;%0A  

Clarify logic around codesGenerated boolean