           row[b] = 0
           break
         else if row[b] isnt 0 then break
+
+  else if direction is 'left'
+    for a in [0...3]
+      for b in [a+1..3]
+
+        if row[a] is 0 then break
+        else if row[a] == row[b]
+          row[a] *= 2
+          row[b] = 0
+          break
+        else if row[b] isnt 0 then break
   row
-
-# console.log mergeCells [4,4,4,4], 'right'
 
 collapseCells = (row, direction) ->
   row = row.filter (ele) -> ele isnt 0


buildBoard = ->
  [0..3].map -> [0..3].map -> 0

# buildBoardSlow = ->
#   board = []
#   for row in [0..3]
#     board[row] = []
#     for col in [0..3]
#       board[row][col] = 0
#   board

generateTile = (board) ->
  value = randomValue()

      # try moving
      newBoard = move(@board, direction)
      printArray newBoard
      # check the move validity, by comparing the original and new board
      if moveIsValid(@board, newBoard)
        console.log "Valid"
        @board = newBoard
        # generate tile
        generateTile(@board)
        showBoard(@board)
        #check game lost
        if isGameOver(@board)
          console.log "YOU LOSE"
        else
          # show board
          showBoard(@board)

      else
        console.log "Invalid"

