scf4 / callbaxx

[Satire]🔥 JS utility library to bring classic callback style programming to synchronous code — ES6? More like ES Sucks.
MIT License
9 stars 1 forks source link

Add modulo math function #12

Closed rbong closed 5 years ago

rbong commented 5 years ago

Hi, great library, I can't ever get enough callbacks!

I think this modulo function could be really useful. Take this elegant FizzBuzz implementation for example.

var modulo = require('callbaxx').modulo;
var isTrue = require('callbaxx').isTrue;

function fizzbuzz(cb) {
  for (var i = 1; i <= 100; i++) {
    modulo(i, 15, function(err, res) {
      isTrue(res === 0, function(err, res) {
        if (res) {
          console.log('FizzBuzz');
        } else {
          modulo(i, 3, function(err, res) {
            isTrue(res === 0, function(err, res) {
              if (res) {
                console.log('Fizz');
              } else {
                modulo(i, 5, function(err, res) {
                  isTrue(res === 0, function(err, res) {
                    if (res) {
                      console.log('Buzz');
                    } else {
                      console.log(i);
                    }
                  });
                });
              }
            });
          });
        }
      });
    });
  }
}

fizzbuzz();
scf4 commented 5 years ago

Thank you for this fantastic contribution! Could you possibly add the FizzBuzz implementation to the /examples dir? The more examples we have, the better.

The sixers currently have a monopoly on the JavaScript ecosystem (including examples and tutorials) and examples like this are one of the only things we really have to show newcomers that there's more to JavaScript than async/await and promises and whatever the new "hot" framework and new replacement for WebPack is... but I digress. Thanks again!

rbong commented 5 years ago

Great idea, I've added it

scf4 commented 5 years ago

Perfect, thanks!