1

,I know how to transform the data I want into one array.

Ie from a model holding geocordinates in one line:

Place.all.map(&:latitude)

[12.34, 12.34, ...]

How can I transform it to make a nested dual array with both latitude and longitude

ie [[12.34,23.34],[23.45,12,23],...]

1 Answer 1

4
Place.all.map{ |place| [place.latitude, place.longitude] }

Sidenotes:

  • all queries are db killers.

  • if you only need two fields, consider using select

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I'm not really using :all. Just for the example, thanks. I have to wait 13 minutes to accept your answer. ;-)

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.