0

I have an array, say with 100 items in it, and I want to filter out all the items between 20-30.

Something like this, but this isn't correct obviously:

myArray.filter_by_indices(20...30)

I searched and searched, and couldn't find an answer.

2
  • 2
    array.removeSubrange(20...30)? Commented Mar 14, 2018 at 14:33
  • 1
    You want to remove those items or keep those items? Commented Mar 14, 2018 at 14:36

1 Answer 1

3

You don't need a filter. You can simply call removeSubrange.

myArray.removeSubrange(20..30)

And for the sake of completeness, here is an option using a filter:

myArray = myArray.enumerated().filter { $0.offset < 20 || $0.offset > 30 }.map { $0.element }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.