1

My array is

 arr = ["wow what", "what anice", "anice day.currently", "day.currently i", "i am", "am in", "in delhi", "delhi but", "but in", "in night", "night i", "i am", "am going", "going to", "to us"]
    arr.each do |el|
     if !el.match('in') && !el.match('is').blank?
      fresh_arr << el
     end

but i have 110k element array and it give 8sec that,s too much time can i do this any another way

Thx

2

3 Answers 3

3

Use delete_if

arr.delete_if do |e|
  e.match('in') && e.match('is').blank?
end
arr
Sign up to request clarification or add additional context in comments.

1 Comment

I think you meant delete_if
3

Try this

arr.reject { |i| i.match('in') || i.match('is').blank? }

Comments

0

You can select all elements you need by doing this

arr.select{|el| !el.match('in') && !el.match('is').blank?}

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.