1

I am trying to generate array as a result of comparison 2 arrays as:

a = %w{a b a e}
b = %w{c d a e}

After comparing it should give result as:

c = [false, false, true, true]

Is there any ruby way which is better than doing a for loop because I have to do this comparison with a lot of arrays.

2 Answers 2

3

This way?

a.zip(b).map { |a, b| a == b }
Sign up to request clarification or add additional context in comments.

Comments

1

Uglier, but just to show an alternative:

a.map.with_index { |aa, i| aa == b[i] }

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.