The Red/Yellow Sequence

Published by Matt in

Write a function that takes a number n and a string s as arguments and returns the nth term of the Red/Yellow sequence. s will ask the function what to return, all, red or yellow.

alt text

Examples

rySeq(2, "all") ➞ 5

rySeq(3, "yellow") ➞ 8

rySeq(28, "red") ➞ 55

rySeq(1, "blue") ➞ -1

Notes

  • If s is not "all", "yellow" or "red", return -1.
  • If n is 0, return 0.
  • n is always a positive integer.
Watch a quick demo on how Edabit works.