Student.js
/**
     * Assigns this student to a workshop in the student's first available slot.
     *
     * @param {workshop} workshop The workshop to add the student to.
     *
     * @throws an error if the student already has workshops in each slot.
     */
Assigns this student to a workshop in the student's first available slot.
@param {workshop} workshop The workshop to add the student to.

@throws an error if the student already has workshops in each slot.
Assigns this student to a workshop in the student ' s first available slot . @param { workshop } workshop The workshop to add the student to . @throws an error if the student already has workshops in each slot .
assignWorkshop(workshop) {
        if (this.fullyAssigned()) {
            throw new Error(
                this.fullName() + " cannot be assigned any more workshops"
            );
        }
        if (this.isAssigned(workshop)) {
            throw new Error("duplicate match");
        }
        const sessionsByFill = workshop.leastFullSessions();
        for (let i = 0; i < sessionsByFill.length; i++) {
            const currentSession = sessionsByFill[i];
            const timeSlot = currentSession.timeSlot;
            if (this.hasTimeSlotFree(timeSlot) && !currentSession.isFull()) {
                workshop.addStudent(this);
                currentSession.addStudent(this);
                this.assignedWorkshops[timeSlot] = workshop;
                return;
            }
        }
        Logger.log("problem found");
        throw new Error("what is wrong with you");
    }
assignWorkshop ( workshop ) { if ( this . fullyAssigned ( ) ) { throw new Error ( this . fullName ( ) + " cannot be assigned any more workshops" ) ; } if ( this . isAssigned ( workshop ) ) { throw new Error ( "duplicate match" ) ; } const sessionsByFill = workshop . leastFullSessions ( ) ; for ( let i = 0 ; i < sessionsByFill . length ; i ++ ) { const currentSession = sessionsByFill [ i ] ; const timeSlot = currentSession . timeSlot ; if ( this . hasTimeSlotFree ( timeSlot ) && ! currentSession . isFull ( ) ) { workshop . addStudent ( this ) ; currentSession . addStudent ( this ) ; this . assignedWorkshops [ timeSlot ] = workshop ; return ; } } Logger . log ( "problem found" ) ; throw new Error ( "what is wrong with you" ) ; }
Assigns this student to a workshop in the student's first available slot.
Assigns this student to a workshop in the student ' s first available slot .
//maybe this can be refactored into a "find available slot" method?