General FizzBuzz

Tell us what’s happening:
When running the tests I get the following:

Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined
Cannot read property 'reduce' of undefined

Which suggests that the rules argument I’m being supplied is not an Array. The list of test cases on the left also suggests something is wrong with the system, providing entries like the following:

'genFizzBuzz('+JSON.stringify(tests[0][0])+','+tests[0][1]+')should return a type.'

So…how do I advance under these circumstances?

Your code so far


function genFizzBuzz (rules, num) {
  return rules.reduce((prev, [mult, str]) => 
      prev += (num % mult === 0) ? str : ''
    , '');
  // Good luck!
}

console.log(
  genFizzBuzz(
    [ [3,"Fizz"] , [5,"Buzz"] ]
    , 15
  )
) 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/general-fizzbuzz

There is a bug in how the tests work on this challenge (and a few others of the Rosetta Code section) that has been fixed on our master branch. When the master branch is finally deployed in the near future, this issue will go away.

That being said, your solution does still not pass the following test:

genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13) should return "13"

Instead yours returns a blank string instead of the number 13.

Good to know.

In the absence of visible test cases, my code is written to conform to the requirements the page provides, namely:

This indcates that Fizz should be printed if the number is a multiple of 3 and Buzz if it is a multiple of 5. If it is a multiple of both then the strings should be concatenated in the order specified in the array. In this case, FizzBuzz if the number is a multiple of 3 and 5.

The second parameter is the number for which the function should return a string as stated above.

For those of us who haven’t been presented FizzBuzz before, the requirement that it return the number when none of the rules are met isn’t intrinsic knowledge. Hopefully the merge to Master happens soon. :smiley: