5 ms·
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.
by minor_nitwit 12y 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.
- geocar 12y agoa 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.