a shorter way to do: ` arr = %w[black brown red orange yellow green blue violet grey white] cols = arr.each_with_index.map {|col , ind| [col, ind.to_s]}.to_h` in ruby

To find a shorter way to convert an array into a hash with indices as values, you can use the with_index method. Here's the updated code:

main.rb
arr = %w[black brown red orange yellow green blue violet grey white]
cols = arr.map.with_index.to_h
100 chars
3 lines

This code is more concise as it combines the map and with_index methods to directly convert the array into a hash with indices as values.

related categories

gistlibby LogSnag