← Back to challenges

Widen the Streets!

JavaScriptHardarraysstringsformatting

Instructions

Given an array of strings depicting a row of buildings, create a function which sets the gap between buildings as a given amount.

Examples

widenStreets([
  "###   ## #",
  "### # ## #",
  "### # ## #",
  "### # ## #",
  "### # ## #"
], 3) ➞ [
  "###       ##   #",
  "###   #   ##   #",
  "###   #   ##   #",
  "###   #   ##   #",
  "###   #   ##   #"
]

widenStreets([
  "## ### ###",
  "## ### ###",
  "## ### ###",
  "## ### ###"
], 2) ➞ [
  "##  ###  ###",
  "##  ###  ###",
  "##  ###  ###",
  "##  ###  ###"
]

widenStreets([
  "# # # # #"
], 2) ➞ [
  "#  #  #  #  #"
]

Notes

  • Buildings may be different sizes.
  • There will always be a starting gap size of one character.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.