← Back to challenges

Fibonacci String

JavaScriptHardarraysstrings

Instructions

A Fibonacci string is a precedence of the Fibonacci series. It works with any two characters of the English alphabet (as opposed to the numbers 0 and 1 in the Fibonacci series) as the initial items and concatenates them together as it progresses similarly to the Fibonacci series.

Examples

fibStr(3, ["j", "h"]) ➞ "j, h, hj"

fibStr(5, ["e", "a"]) ➞ "e, a, ae, aea, aeaae"

fibStr(6, ["n", "k"]) ➞ "n, k, kn, knk, knkkn, knkknknk"

Notes

  • All values for n will be at least 2.
  • A recursive version of this challenge can be found via this link.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.