Characters and ASCII Code Hash

Published by Helen Yu in

Write a function that transforms an array of characters into an array of hashes, where:

  1. The keys are the characters themselves.
  2. The values are the ASCII codes of those characters.

Examples

to_hash(["a", "b", "c"]) ➞ [{"a" => 97}, {"b" => 98}, {"c" => 99}]

to_hash(["^"]) ➞ [{"^" => 94}]

to_hash([]) ➞ []

Notes

N/A

Watch a quick demo on how Edabit works.