← Back to challenges

Construct and Deconstruct

JavaScriptHardlanguage_fundamentalsstringsarraysloops

Instructions

Given a string, create a function which outputs an array, building and deconstructing the string letter by letter. See the examples below for some helpful guidance.

Examples

constructDeconstruct("Hello") ➞ [
  "H",
  "He",
  "Hel",
  "Hell",
  "Hello",
  "Hell",
  "Hel",
  "He",
  "H"
]

constructDeconstruct("innokodakademija") ➞ [
  "e",
  "ed",
  "eda",
  "edab",
  "edabi",
  "innokodakademija",
  "edabi",
  "edab",
  "eda",
  "ed",
  "e"
]

constructDeconstruct("the sun") ➞ [
  "t",
  "th",
  "the",
  "the ",
  "the s",
  "the su",
  "the sun",
  "the su",
  "the s",
  "the ",
  "the",
  "th",
  "t"
]

Notes

Include spaces (see example #3).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The Sweetest Ice Cream