 (defn- timetable-row-empty?
   "Returns true if there is no lesson for a given day and row in `Timetable`.
    Returns false otherwise."
-  [day rowNum]
-  (empty? (timetable-get-day-row day rowNum)))
+  ([ttRow] (empty? ttRow))
+
+  ([day rowNum] (empty? (timetable-get-day-row day rowNum))))
 
 (defn- timetable-row-not-empty?
   "Returns true if there at least one lesson for a given day and row in
    `Timetable`. Returns false otherwise."
-  [day rowNum]
-  (not (timetable-row-empty? day rowNum)))
+  ([ttRow] (not (timetable-row-empty? ttRow)))
+
+  ([day rowNum] (not (timetable-row-empty? day rowNum))))
 
 (defn- timetable-row-get-lessons-satisfying-pred
   "Returns a sequence of vectors of `TimetableLessonInfo` object and the

  (doseq [day affectedDaysSet]
    (let [nrRows          (get-nr-rows-in-timetable-day day)

          {:keys [emptyRowsVec nonEmptyRowsVec]}
          (reduce (fn [rPart rowIdx]
                    (if (timetable-row-empty? day rowIdx)
                        (update-in rPart [:emptyRowsVec] #(conj %1 rowIdx))
                        (update-in rPart [:nonEmptyRowsVec] #(conj %1 rowIdx))))
                  {:emptyRowsVec [], :nonEmptyRowsVec []}
                  (range nrRows))

          nrEmptyRows     (count emptyRowsVec)
          nrNonEmptyRows  (- nrRows nrEmptyRows)
          $day            (nth HTML-Timetable day)
          $thElem         (.find $day "tr > th")]
      (.log js/console (str "day = " day ", emptyRowsVec = "
                            (.stringify js/JSON (clj->js emptyRowsVec))
                            ", nonEmptyRowsVec = "
                            (.stringify js/JSON (clj->js nonEmptyRowsVec))))
      (set! Timetable
            (update-in Timetable [day]
                       (fn [ttDay]
                         (vec (map (fn [rowIdx] (nth ttDay rowIdx))
                                   (cond (>= nrNonEmptyRows 2)
                                         nonEmptyRowsVec

                                         (= nrNonEmptyRows 1)
                                         [(first nonEmptyRowsVec)
                                          (first emptyRowsVec)]

                                         :else
                                         (take 2 emptyRowsVec)))))))
      ; shift <th> element to the new 0th row
      (if (and (zero? (first emptyRowsVec)) (> nrNonEmptyRows 0))
          (prepend (nth (children $day "tr") (first nonEmptyRowsVec)) $thElem))

      ; remove empty <tr> elements
      (let [rowsToRemove
            (cond (>= nrNonEmptyRows 2) emptyRowsVec
                  (=  nrNonEmptyRows 1) (rest emptyRowsVec)
                  :else                 (drop 2 emptyRowsVec))]
        (doseq [[idx rowIdx] (map vector (range (count rowsToRemove))
                                  rowsToRemove)]
          (.remove (nth (children $day "tr") (- rowIdx idx)))))

      (if (and (= nrNonEmptyRows 1)
               (zero? (first emptyRowsVec)))
          (let [$trArray (children $day "tr")]
            (.log js/console "Am gonna swap this shit man")
            (.log js/console (str "$trArray = " $trArray ", 0th = " (nth $trArray 0) ", 1st = " (nth $trArray 1)))

  [day rowNum]
  (nth (timetable-get-day day) rowNum))

; Returns the total number of rows for a given day in the Timetable.
(defmulti get-nr-rows-in-timetable-day number? :default false)

; Argument argument is a a 0-indexed integer representing the day, where
; 0 = Monday, 1 = Tuesday, until 4 = Friday
(defmethod get-nr-rows-in-timetable-day true [day]
  [day]
  (count (timetable-get-day day)))

; Argument is a Timetable row returned by the `tiemtable-get-day-row` function
(defmethod get-nr-rows-in-timetable-day false [ttDay]
  (count ttDay))

(def ^{:doc     "HTML string for the <td> elements in a <tr> on the Timetable
                 Builder page"
