daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const isDivisibleBy = divisor => dividend => dividend % divisor === 0;
  2. const isFizzBuzz = num => isDivisibleBy(15)(num) && num !== 0;
  3. const isFizz = num => isDivisibleBy(3)(num) && num !== 0;
  4. const isBuzz = num => isDivisibleBy(5)(num) && num !== 0;
  5.  
  6. const fizzBuzz = (num, current = 0) => {
  7.   if (current === num + 1 || num < 0) return;
  8.  
  9.   if (isFizzBuzz(current)) console.log('fizzbuzz');
  10.   else if (isFizz(current)) console.log('fizz');
  11.   else if (isBuzz(current)) console.log('buzz');
  12.   else console.log(current);
  13.  
  14.   fizzBuzz(num, current + 1);
  15. };
  16.  
  17. fizzBuzz(100);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top