jeudi 23 août 2018

Testing simple FizzBuzz function inJS

I have a simple FizzBuzz function, and have to implement test for it, spent whole day, coudn't figure out how to implement it properly. Its throws an error.

function* sequenceFizzBuzz(start, step) {
  start = start || 0;
  step = step || 1;


  if ((start + step) % 3 === 0) {

  if ((start + step) % 5 === 0) {
    yield "FizzBuzz"
 }
    yield 'Buzz'
 } else if ((start + step) % 5 === 0) {
   yield 'Fizz'
 } else {
 yield start += step;
}
}


test('Should to get FizzBuzz or just Fizz or Buzz', () => {
 expect(sequenceFizzBuzz(10, 5)).toBe("FizzBuzz")
});

Aucun commentaire:

Enregistrer un commentaire