Fibonacci Word

Published by Deep Xavier in

A Fibonacci Word is a specific sequence of binary digits (or symbols from any two-letter alphabet). The Fibonacci Word is formed by repeated concatenation in the same way that the Fibonacci numbers are formed by repeated addition.

Create a function that takes a number n as an argument and returns the first n elements of the Fibonacci Word sequence.

If n < 2, the function must return "invalid".

Examples

fiboWord(1) ➞ "invalid"

fiboWord(3) ➞ "b, a, ab"

fiboWord(7) ➞ "b, a, ab, aba, abaab, abaababa, abaababaabaab"

Notes

  • You can try solving this challenge using a recursive approach.
  • A recursive version of this challenge can be found here.
Watch a quick demo on how Edabit works.