tbeseda
10/3/2013 - 11:07 PM

Given a number of rows and columns generate spreadsheet style coordinates. i.e. [A1, B1, C1...BJ9, BK9, BL9]

Given a number of rows and columns generate spreadsheet style coordinates. i.e. [A1, B1, C1...BJ9, BK9, BL9]

generate_coordinates = (rows, columns) ->
  generated_coordinates = []
  alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')

  for i in [1..rows]
    for n in [0..(columns-1)]
      a = if n < 26 then alphabet[n] else alphabet[Math.floor(n/26)-1] + alphabet[n%26]
      generated_coordinates.push(a + i)

coordinates = generate_coordinates(8, 63)
console.log(coordinates.length + ' coords generated!') # 504 coords generated!