6 kyu

Custom FizzBuzz Array

699 of 3,664ogryzek

Description:

Write a function that returns a (custom) FizzBuzz sequence of the numbers 1 to 100.

The function should be able to take up to 4 arguments:

  • The 1st and 2nd arguments are strings, "Fizz" and "Buzz" by default;
  • The 3rd and 4th arguments are integers, 3 and 5 by default.

Thus, when the function is called without arguments, it will return the classic FizzBuzz sequence up to 100:

[ 1, 2, "Fizz", 4, "Buzz", "Fizz", 7, ... 14, "FizzBuzz", 16, 17, ... 98, "Fizz", "Buzz" ]

When the function is called with (up to 4) arguments, it should return a custom FizzBuzz sequence, for example:

('Hey', 'There')      -->  [ 1, 2, "Hey", 4, "There", "Hey", ... ]
('Foo', 'Bar', 2, 3)  -->  [ 1, "Foo", "Bar", "Foo", 5, "FooBar", 7, ... ]

Examples

fizz_buzz_custom[15]                         # returns 16
fizz_buzz_custom[44]                         # returns "FizzBuzz" (45 is divisible by 3 and 5)
fizz_buzz_custom('Hey', 'There')[25]         # returns 26
fizz_buzz_custom('Hey', 'There')[11]         # returns "Hey" (12 is divisible by 3)
fizz_buzz_custom("What's ", "up?", 3, 7)[80] # returns "What's " (81 is divisible by 3)
fizzBuzzCustom()[15]                         // returns 16
fizzBuzzCustom()[44]                         // returns "FizzBuzz" (45 is divisible by 3 and 5)
fizzBuzzCustom('Hey', 'There')[25]         // returns 26
fizzBuzzCustom('Hey', 'There')[11]         // returns "Hey" (12 is divisible by 3)
fizzBuzzCustom("What's ", "up?", 3, 7)[80] // returns "What's " (81 is divisible by 3)
fizz_buzz_custom()[15]                         # returns 16
fizz_buzz_custom()[44]                         # returns "FizzBuzz" (45 is divisible by 3 and 5)
fizz_buzz_custom('Hey', 'There')[25]         # returns 26
fizz_buzz_custom('Hey', 'There')[11]         # returns "Hey" (12 is divisible by 3)
fizz_buzz_custom("What's ", "up?", 3, 7)[80] # returns "What's " (81 is divisible by 3)
Arrays
Logic
Fundamentals

Stats:

CreatedApr 21, 2014
PublishedApr 21, 2014
Warriors Trained6637
Total Skips1423
Total Code Submissions26042
Total Times Completed3664
Ruby Completions699
JavaScript Completions2185
Python Completions721
Rust Completions130
Total Stars110
% of votes with a positive feedback rating88% of 480
Total "Very Satisfied" Votes380
Total "Somewhat Satisfied" Votes85
Total "Not Satisfied" Votes15
Ad
Contributors
  • ogryzek Avatar
  • jhoffner Avatar
  • anter69 Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • user1799785 Avatar
  • albertogcmr Avatar
  • Haksell Avatar
Ad