0

I am working on implementing graphs in rails app. There is a specific data format requirement. I am have the data as below:

["counting", [50, 50, 50, 50]]

The required format is

{:name=>"counting", :data=>[350, 350, 250, 150]}

Please help me achieve this.

1 Answer 1

4

This is simple

array = ["counting", [50, 50, 50, 50]]
required_format = { name: array.first, data: array.last } #=> {:name=>"counting", :data=>[50, 50, 50, 50]}

Alternatively

array = ["counting", [50, 50, 50, 50]]
keys = [:name, :data]
required_format = keys.zip(array).to_h #=> {:name=>"counting", :data=>[50, 50, 50, 50]}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.