How can you remove every nth element of a string?
I’m guessing you would use the drop function in some kind of way.
Like this drops the first n, how can you change this so only drops the nth, and then the nth after that, and so on, rather than all?
dropthem n xs = drop n xs
Here’s what the function does:
zip [1..]is used to index all items in the list, so e.g.zip [1..] "foo"becomes[(1,'f'), (2,'o'), (3,'o')].The indexed list is then processed with a right fold which accumulates every element whose index is not divisible by
n.Here’s a slightly longer version that does essentially the same thing, but avoids the extra memory allocations from
zip [1..]and doesn’t need to calculate modulus.