Skip to main content
Code Review

Return to Revisions

3 of 3
Commonmark migration

Cut each N symbol from array

What is the most efficient and productive way to cut each N symbol from a string?

For instance,

n = 5;

str = '1234A1234B1234C';

result: "123412341234"

This is my approach:

def delete_each_n(str, n)
 i = n
 str.length/n.times do
 str.slice!(i-1)
 i += (n - 1)
 end
 str
end
kwaigon
  • 123
  • 5
lang-rb

AltStyle によって変換されたページ (->オリジナル) /