dimention parser

by Johan Vandeplas

CoffeeScript

sa = [
  'L x W x H'
  'LxWxH'
  'LxWxHm'
  'LxWxH m'
  'L x W x H m'
  'L x W x Hcm'
  'L x W x Hcm'
  'L x W in'
  'L x W inch'
  'L x W x'
]
L = '10.5'
W = '54.5'
H = '198,555.55'

splitQuantityUnit = (s) ->
  index = s.search(/[A-Za-z]*$/)
  [
    s.substring(0, index)
    s.substring(index)
  ]

i = 0
for s in sa
  s = s.replace(/L/g, L)
  s = s.replace(/W/g, W)
  s = s.replace(/H/g, H)
  #remove spaces
  a = s.replace(/ /g, '').split('x')
  [q, u] = splitQuantityUnit(a[a.length - 1])
  a[a.length - 1] = q
  a[4] = u
  console.log a