Coder Social home page Coder Social logo

fizzbuzzwithoutconditionals's Introduction

Fizz Buzz Kata Implementation Without Conditionals

This code demonstrates a possible Fizz Buzz Kata implementation without using if conditionals and instead working with dictionaries.

The code was implemented via TDD to initially produce the obvious solution using if statements and afterwards refactored step-by-step to remove all conditionals and replace them with setting up dictionaries for producing the result.

This solution of the Kata was only created to prove that it's possible to not use any conditional statements or loops to achieve the expected behaviour.

Considerations of clean code such as readability have been not been completely disregarded but were not put in focus ;-)

Note: the amount of data-driven test cases should usually of course not be necessary and are rather provided to demonstrate to the reader that the solution works ;-)

PS: the goal of the original Kata is to also produce a list of all numbers from 1 to 100. This part was intentionally skipped and is left to the readers imagination.

Excercise 1 - Make the code even simpler

Assuming that the requirements are set in stone and will not change, think of how this code could be simplified while still not using any conditionals or loops.

Excercise 2 - Make the code extensible

How could we make the code extensible so that you can easily define different or new words to be called for different numbers.

E.g. calling "Moo" if the number is divisible by 7 and calling "FizzBuzzMoo" if it is divisible by 3, 5 and 7.

To do so we shall follow the open closed principle so it should be able to set this up without modifying the inners of the FizzBuzz class.

Is it even possible to achieve this without conditionals? I don't know, let's find out ๐Ÿ˜‰

Note: feel free to refactor from this code or start the solution from scratch. The tests will serve as a safety net to tell you when you went wrong.

fizzbuzzwithoutconditionals's People

Contributors

afhswe avatar andi-huetter-tricentis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.