0

I have an array @a = [[9, 15], [], []]

I need to make it [9,15] using map method. How it is possible?

I have tried the below statement,

@a.map{|array| array.collect{|element| element} if array.any?}.compact

But giving [[9,15]] as output. Can anyone just help me out. Thanks :)-

1 Answer 1

5

I'm not sure about the requirements, but this gives the desired result

[[9, 15], [], []].flatten
Sign up to request clarification or add additional context in comments.

3 Comments

is it a proper ruby method?
If that is the answer, @RajeshCO, maybe you should accept it?
Sure, I was waiting for it

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.