RosettaCodeData/Task/Run-length-encoding/CoffeeScript/run-length-encoding-2.coffeescript
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

8 lines
278 B
Text

encode = (str, offset = 75) ->
str.replace /(.)\1*/g, (w) ->
w[0] + String.fromCharCode(offset+w.length)
decode = (str, offset = 75) ->
str.split('').map((w,i) ->
if not (i%2) then w else new Array(+w.charCodeAt(0)-offset).join(str[i-1])
).join('')