Y
Hacker News
new
|
ask
|
show
|
jobs
by
minor_nitwit
4254 days ago
that seems overly complicated for ruby if a is a file.
c = []; a.lines{c << a.pos}
As far as $, you may know it from Regex as the new line indicator.
1 comments
geocar
4253 days ago
a is a mapped string. You could do:
c=[];n=0;a.lines{|x|c<<(n+=x.size)-1}
but $"\n" wasn't special, and this allocates tons of memory. tinco's implementation is much closer to what k is actually doing.
link