           row[b] = 0
           break
         else if row[b] isnt 0 then break
+    row
 
+  if direction is 'right'
+    merge row
   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
+    merge(row.reverse()).reverse()
 
 collapseCells = (row, direction) ->
   row = row.filter (ele) -> ele isnt 0

showBoard = (board) ->
  for row in [0..3]
    for col in [0..3]
      $(".r#{row}.c#{col} > div").html(board[row][col])

printArray = (array) ->
  console.log "--- Start ---"


mergeCells = (row, direction) ->

  merge = (row) ->
    for a in [3...0]
      for b in [a-1..0]

