Designing Rugs

Published by Deep Xavier 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 null is given).
  • The character passed in through the proc repeating n times.

Examples

makeRug(2, 1, "tct") ➞ [
  "tct",
  "tct"
]

makeRug(3, 5, null) ➞ [
  "#####",
  "#####",
  "#####"
]

makeRug(3, 5, "$")  ➞ [
  "$$$$$",
  "$$$$$",
  "$$$$$"
]

makeRug(2, 6, "A")  ➞ [
  "AAAAAA",
  "AAAAAA"
]

Notes

The use of Optional container object is required for this challenge.

Watch a quick demo on how Edabit works.