Designing Rugs

Published by Helen Yu in

Write a function that accepts the width and height (m, n) and an optional proc s and generates an array with m elements. Each element is a string consisting of either:

  • The default character (hash #) repeating n times (if no proc is given).
  • The character passed in through the proc repeating n times.

Examples

make_rug(3, 5) ➞ [
  "#####",
  "#####",
  "#####"
]

make_rug(3, 5){|x| x = "$"}  ➞ [
  "$$$$$",
  "$$$$$",
  "$$$$$"
]

make_rug(2, 2){|x| x = "A"}  ➞ [
  "AA",
  "AA"
]

Notes

N/A

Watch a quick demo on how Edabit works.